Author Topic: set parameters and count blocks in associative array  (Read 4154 times)

0 Members and 1 Guest are viewing this topic.

Eycki

  • Guest
set parameters and count blocks in associative array
« on: December 09, 2011, 07:16:43 AM »
Hello, I am wondering if it is possible to approach the 2012 Array from AutoCAD and set its properties with .NET
I haven't found a solution on the internet yet, so at this moment I'm using it with the SendStringToExecute command.  It does the job but it's a lot slower as it could be with proper coding.
« Last Edit: December 09, 2011, 09:49:59 AM by Eycki »

kaefer

  • Guest
Re: Approaching Array 2012
« Reply #1 on: December 09, 2011, 07:23:36 AM »
Hello, I am wondering if it is possible to approach the 2012 Array from AutoCAD and set its properties with .NET

The keyword is Associative Array, like that found here.

Eycki

  • Guest
Re: Approaching Array 2012
« Reply #2 on: December 09, 2011, 07:41:56 AM »
Hello, I am wondering if it is possible to approach the 2012 Array from AutoCAD and set its properties with .NET

The keyword is Associative Array, like that found here.

I see this article is pretty recent , that is why I didnt found it a couple months ago :-)
Thanks a lot!

Eycki

  • Guest
Re: Approaching Array 2012
« Reply #3 on: December 09, 2011, 09:48:56 AM »
Hello, I am wondering if it is possible to approach the 2012 Array from AutoCAD and set its properties with .NET

The keyword is Associative Array, like that found here.
Do you have any idea how to count blocks in an associative array?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: set parameters and count blocks in associative array
« Reply #4 on: December 09, 2011, 06:28:33 PM »
Yes
Code - C#: [Select]
  1. [Wrapper("AcDbAssocArrayPathParameters"), TypeDescriptionProvider("Autodesk.AutoCAD.ComponentModel.TypeDescriptionProvider`1[[Autodesk.AutoCAD.DatabaseServices.AssocArrayPathParameters, acdbmgd]], acdbmgd")]
  2. public class AssocArrayPathParameters : AssocArrayCommonParameters
  3. {
  4.     // Methods
  5.     public AssocArrayPathParameters();
  6.     protected internal AssocArrayPathParameters(IntPtr unmanagedPointer, [MarshalAs(UnmanagedType.U1)] bool autoDelete);
  7.     public AssocArrayPathParameters(double itemSpacing, double rowSpacing, double levelSpacing, int itemCount, int rowCount, int levelCount, double rowElevation);
  8.     public double GetEndOffset(out string expression, out string evaluatorId);
  9.     internal unsafe AcDbAssocArrayPathParameters* GetImpObj();
  10.     public int GetItemCount(out string expression, out string evaluatorId);
  11.     public double GetItemSpacing(out string expression, out string evaluatorId);
  12.     public double GetStartOffset(out string expression, out string evaluatorId);
  13.     public void SetEndOffset(double offset, string expression, string evaluatorId);
  14.     public void SetItemCount(int count, string expression, string evaluatorId);
  15.     public void SetItemSpacing(double spacing, string expression, string evaluatorId);
  16.     public void SetStartOffset(double offset, string expression, string evaluatorId);
  17.  
  18.     // Properties
  19.     public bool AlignItems { [return: MarshalAs(UnmanagedType.U1)] get; [param: MarshalAs(UnmanagedType.U1)] set; }
  20.     public double EndOffset { get; set; }
  21.     public int ItemCount { get; set; }
  22.     public double ItemSpacing { get; set; }
  23.     public MethodType Method { get; set; }
  24.     public EdgeRef Path { get; set; }
  25.     public bool PathDirection { [param: MarshalAs(UnmanagedType.U1)] set; }
  26.     public double StartOffset { get; set; }
  27.  
  28.     // Nested Types
  29.     public enum MethodType
  30.     {
  31.         Divide,
  32.         Measure
  33.     }
  34. }
  35.  

Code - C#: [Select]
  1. [TypeDescriptionProvider("Autodesk.AutoCAD.ComponentModel.TypeDescriptionProvider`1[[Autodesk.AutoCAD.DatabaseServices.AssocArrayCommonParameters, acdbmgd]], acdbmgd"), Wrapper("AcDbAssocArrayCommonParameters")]
  2. public abstract class AssocArrayCommonParameters : AssocArrayParameters
  3. {
  4.     // Methods
  5.     protected internal AssocArrayCommonParameters(IntPtr unmanagedPointer, [MarshalAs(UnmanagedType.U1)] bool autoDelete);
  6.     internal unsafe AcDbAssocArrayCommonParameters* GetImpObj();
  7.     public int GetLevelCount(out string expression, out string evaluatorId);
  8.     public double GetLevelSpacing(out string expression, out string evaluatorId);
  9.     public int GetRowCount(out string expression, out string evaluatorId);
  10.     public double GetRowElevation(out string expression, out string evaluatorId);
  11.     public double GetRowSpacing(out string expression, out string evaluatorId);
  12.     public void SetLevelCount(int count, string expression, string evaluatorId);
  13.     public void SetLevelSpacing(double spacing, string expression, string evaluatorId);
  14.     public void SetRowCount(int count, string expression, string evaluatorId);
  15.     public void SetRowElevation(double value, string expression, string evaluatorId);
  16.     public void SetRowSpacing(double spacing, string expression, string evaluatorId);
  17.  
  18.     // Properties
  19.     public Vector3d BaseNormal { get; set; }
  20.     public FaceRef BasePlane { get; set; }
  21.     public VertexRef BasePoint { get; set; }
  22.     public int LevelCount { get; set; }
  23.     public double LevelSpacing { get; set; }
  24.     public int RowCount { get; set; }
  25.     public double RowElevation { get; set; }
  26.     public double RowSpacing { get; set; }
  27. }
  28.  
« Last Edit: December 09, 2011, 06:31:38 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Eycki

  • Guest
Re: set parameters and count blocks in associative array
« Reply #5 on: December 10, 2011, 08:41:13 AM »
The sample code that is downloadable on this page helped me a lot: http://through-the-interface.typepad.com/through_the_interface/2011/03/new-apis-in-autocad-2012.html

Eycki

  • Guest
Re: set parameters and count blocks in associative array
« Reply #6 on: December 13, 2011, 04:47:51 AM »
OK, I made it work to create an associative array from a dynamic block which I modify first before taking it in the array.

What I want to do now is make a command that modifies parameters which includes replacing the source item thru a new blockreference that I import.  Also the rowspacing, rowcount, columnspacing and columncount will get new values.
To do this I actually delete the array and creat a new one on the same basepoint?  Which is the best solution?

Thanks in advance!


Yes
Code - C#: [Select]
  1. [Wrapper("AcDbAssocArrayPathParameters"), TypeDescriptionProvider("Autodesk.AutoCAD.ComponentModel.TypeDescriptionProvider`1[[Autodesk.AutoCAD.DatabaseServices.AssocArrayPathParameters, acdbmgd]], acdbmgd")]
  2. public class AssocArrayPathParameters : AssocArrayCommonParameters
  3. {
  4.     // Methods
  5.     public AssocArrayPathParameters();
  6.     protected internal AssocArrayPathParameters(IntPtr unmanagedPointer, [MarshalAs(UnmanagedType.U1)] bool autoDelete);
  7.     public AssocArrayPathParameters(double itemSpacing, double rowSpacing, double levelSpacing, int itemCount, int rowCount, int levelCount, double rowElevation);
  8.     public double GetEndOffset(out string expression, out string evaluatorId);
  9.     internal unsafe AcDbAssocArrayPathParameters* GetImpObj();
  10.     public int GetItemCount(out string expression, out string evaluatorId);
  11.     public double GetItemSpacing(out string expression, out string evaluatorId);
  12.     public double GetStartOffset(out string expression, out string evaluatorId);
  13.     public void SetEndOffset(double offset, string expression, string evaluatorId);
  14.     public void SetItemCount(int count, string expression, string evaluatorId);
  15.     public void SetItemSpacing(double spacing, string expression, string evaluatorId);
  16.     public void SetStartOffset(double offset, string expression, string evaluatorId);
  17.  
  18.     // Properties
  19.     public bool AlignItems { [return: MarshalAs(UnmanagedType.U1)] get; [param: MarshalAs(UnmanagedType.U1)] set; }
  20.     public double EndOffset { get; set; }
  21.     public int ItemCount { get; set; }
  22.     public double ItemSpacing { get; set; }
  23.     public MethodType Method { get; set; }
  24.     public EdgeRef Path { get; set; }
  25.     public bool PathDirection { [param: MarshalAs(UnmanagedType.U1)] set; }
  26.     public double StartOffset { get; set; }
  27.  
  28.     // Nested Types
  29.     public enum MethodType
  30.     {
  31.         Divide,
  32.         Measure
  33.     }
  34. }
  35.  

Code - C#: [Select]
  1. [TypeDescriptionProvider("Autodesk.AutoCAD.ComponentModel.TypeDescriptionProvider`1[[Autodesk.AutoCAD.DatabaseServices.AssocArrayCommonParameters, acdbmgd]], acdbmgd"), Wrapper("AcDbAssocArrayCommonParameters")]
  2. public abstract class AssocArrayCommonParameters : AssocArrayParameters
  3. {
  4.     // Methods
  5.     protected internal AssocArrayCommonParameters(IntPtr unmanagedPointer, [MarshalAs(UnmanagedType.U1)] bool autoDelete);
  6.     internal unsafe AcDbAssocArrayCommonParameters* GetImpObj();
  7.     public int GetLevelCount(out string expression, out string evaluatorId);
  8.     public double GetLevelSpacing(out string expression, out string evaluatorId);
  9.     public int GetRowCount(out string expression, out string evaluatorId);
  10.     public double GetRowElevation(out string expression, out string evaluatorId);
  11.     public double GetRowSpacing(out string expression, out string evaluatorId);
  12.     public void SetLevelCount(int count, string expression, string evaluatorId);
  13.     public void SetLevelSpacing(double spacing, string expression, string evaluatorId);
  14.     public void SetRowCount(int count, string expression, string evaluatorId);
  15.     public void SetRowElevation(double value, string expression, string evaluatorId);
  16.     public void SetRowSpacing(double spacing, string expression, string evaluatorId);
  17.  
  18.     // Properties
  19.     public Vector3d BaseNormal { get; set; }
  20.     public FaceRef BasePlane { get; set; }
  21.     public VertexRef BasePoint { get; set; }
  22.     public int LevelCount { get; set; }
  23.     public double LevelSpacing { get; set; }
  24.     public int RowCount { get; set; }
  25.     public double RowElevation { get; set; }
  26.     public double RowSpacing { get; set; }
  27. }
  28.  

kaefer

  • Guest
Re: set parameters and count blocks in associative array
« Reply #7 on: December 13, 2011, 06:03:48 AM »
What I want to do now is make a command that modifies parameters which includes replacing the source item thru a new blockreference that I import.

What happens if you
- select your AssocArray,
- use the GetParameters() method to obtain an AssocArrayParameters object,
- downcast that to AssocArrayPathParameters,
- try to modify it according to your wishes,
- and finally call the Commit() method on AssocArrayPathParameters?

Example in F#, I hope you'll get the gist:
Code: [Select]
let selectAnArray (ed : Editor) =
    let peo = new PromptEntityOptions("\nSelect an Associative Array: ")
    let per = ed.GetEntity peo
    if per.Status = PromptStatus.OK then
        if AssocArray.IsAssociativeArray per.ObjectId then
            Some per.ObjectId             
        else
            ed.WriteMessage("\nNot an Associative Array, please try again...")
            None
    else None

[<CommandMethod "ChangeItemCount">]
let changeItemCount() =
    let db = acadApp.DocumentManager.MdiActiveDocument.Database
    let ed = acadApp.DocumentManager.MdiActiveDocument.Editor
       
    match selectAnArray ed with
    | None -> ()
    | Some oid ->
        let array = AssocArray.GetAssociativeArray oid
        match array.GetParameters() with
        | :? AssocArrayPathParameters as p ->
            let pir =
                new PromptIntegerOptions(
                    "New value for ItemCount",
                    AllowNegative = false,
                    AllowZero = false,
                    DefaultValue = p.ItemCount,
                    UseDefaultValue = true )
                |> ed.GetInteger
            if pir.Status = PromptStatus.OK then
                p.ItemSpacing <- p.ItemSpacing * float p.ItemCount / float pir.Value
                p.ItemCount <- pir.Value
                p.Commit()
                AssocManager.EvaluateTopLevelNetwork(db, null, 0)
                |> ignore
        | _ -> ()

Edit: Commit() and example added.
« Last Edit: December 13, 2011, 04:27:49 PM by kaefer »