• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Active Member
    MarcioCartacho
    Posts: 9
    Registered: ‎04-18-2012

    I have difficulties in handling API AutoCAD.Net using Dynamic Blocks

    362 Views, 9 Replies
    07-19-2012 07:05 AM

    Please, I have difficulties in handling API AutoCAD.Net using Dynamic Blocks. Could you help me? Thanks in advance.
    I'm trying to modify the configuration of a given dynamic block. The goal is to access the property Table1 Block Dynamic Block and change its value to an existing one.
    You can navigate between the records from Table1 Block? With this code below I have managed to navigate between the dynamic properties of the block and its values​​, but I can not make the property value set in the block table1.
    I tried an example of the link: http://through-the-interface.typepad...blocks/page/3/ however it still fails.
    If you have something that can help me I would be very grateful! Attached is a file with dynamic block if you can help me ...

    [CommandMethod("getprop")]
    static public void GetProps()
    {
      Document doc = Application.DocumentManager.MdiActiveDocument; 
      Database db = doc.Database; 
      Editor ed = doc.Editor;
      PromptEntityOptions peo = 
       new PromptEntityOptions("\nSelecione o Bloco: ");
      peo.SetRejectMessage("\nIsso não é um Bloco.");
      peo.AddAllowedClass(typeof(BlockReference), false);
      PromptEntityResult per = ed.GetEntity(peo); 
      if (per.Status != PromptStatus.OK) return;
      ObjectId sourceId = per.ObjectId;
      using (Transaction tr = db.TransactionManager.StartTransaction())
      {
        BlockReference brF = 
         (BlockReference)tr.GetObject(sourceId, OpenMode.ForRead);
        if (brF != null && brF.IsDynamicBlock) 
         foreach (DynamicBlockReferenceProperty prop in brF.DynamicBlockReferencePropertyCollection)
           ed.WriteMessage(string.Format("\n{0}: {1}: ", prop.PropertyName, prop.Value)); 
           tr.Commit();
      }
    }


     Thank you! 

    Metso Minerals

    Márcio Lourenço Cartacho
    C.A.D application Developer
    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,334
    Registered: ‎10-08-2008

    Re: I have difficulties in handling API AutoCAD.Net using Dynamic Blocks

    07-19-2012 09:10 AM in reply to: MarcioCartacho

    You have to check IsDynamic property for BlockTableRecord before

     

            [CommandMethod("getprop")]
            static public void GetProps()
            {
                Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                Editor ed = doc.Editor;
                PromptEntityOptions peo =
                 new PromptEntityOptions("\nSelecione o Bloco: ");
                peo.SetRejectMessage("\nIsso não é um Bloco.");
                peo.AddAllowedClass(typeof(BlockReference), false);
                PromptEntityResult per = ed.GetEntity(peo);
                if (per.Status != PromptStatus.OK) return;
                ObjectId sourceId = per.ObjectId;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
    
                    BlockReference brF = (BlockReference)tr.GetObject(sourceId, OpenMode.ForRead);
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(brF.BlockTableRecord, OpenMode.ForRead);
                    if (btr != null && btr.IsDynamicBlock)
                    {
                        foreach (DynamicBlockReferenceProperty prop in brF.DynamicBlockReferencePropertyCollection)
                            ed.WriteMessage(string.Format("\n{0}: {1}: ", prop.PropertyName, prop.Value));
                        tr.Commit();
                    }
                }
            }

     

    ~'J'~

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Active Member
    MarcioCartacho
    Posts: 9
    Registered: ‎04-18-2012

    Re: I have difficulties in handling API AutoCAD.Net using Dynamic Blocks

    07-19-2012 12:25 PM in reply to: Hallex

    Thank you for your attention Hallex.

     

    The real objective is modify the value of the property Block Table1.

     

    prop.Value = 3 for example

    or

     

    prop.Value= 4 for example or 5, 6, ....

     

    this link show example of how modify this value, but Iam not to apply in my code.

    http://through-the-interface.typepad.com/through_the_interface/2009/03/painting-properties-between-d...

     

    Thanks for your attention.

     

    Metso Minerals

    Márcio Lourenço Cartacho
    C.A.D application Developer
    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,334
    Registered: ‎10-08-2008

    Re: I have difficulties in handling API AutoCAD.Net using Dynamic Blocks

    07-19-2012 02:26 PM in reply to: MarcioCartacho

    I tried to get values from your drawing,

    seems to me next code is working:

     

           [CommandMethod("getprop")]
            static public void GetProps()
            {
                Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                Editor ed = doc.Editor;
                PromptEntityOptions peo =
                 new PromptEntityOptions("\nSelecione o Bloco: ");
                peo.SetRejectMessage("\nIsso não é um Bloco.");
                peo.AddAllowedClass(typeof(BlockReference), false);
                PromptEntityResult per = ed.GetEntity(peo);
                if (per.Status != PromptStatus.OK) return;
                ObjectId sourceId = per.ObjectId;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
    
                    BlockReference brF = (BlockReference)tr.GetObject(sourceId, OpenMode.ForRead);
                    if (brF.IsDynamicBlock){
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(brF.DynamicBlockTableRecord, OpenMode.ForRead);
                    if (btr != null && btr.IsDynamicBlock)
                    {
                        foreach (DynamicBlockReferenceProperty prop in brF.DynamicBlockReferencePropertyCollection)
                        {
                            ed.WriteMessage(string.Format("\n{0}: {1}: ", prop.PropertyName, prop.Value));
                            if (prop.PropertyName == "COMPRIMENTO")
                            {
                                prop.Value = 1500.0;
                            }
                            if (prop.PropertyName == "Distance2")
                            {
                                prop.Value = 900.0;
                            }
                            // ---   change other stuffs here   ---  //
                        }
                    }
                        tr.Commit();
                    }
                }
            }
    
    
    //Block Table1: 12:
    //COMPRIMENTO: 3000:
    //Distance2: 118.110236220472:
    //Origin: (-1.20792265079217E-13,200,0):
    //Visibility1: SEM:
    //Desloc: 28.3464566929134:
    //Origin: (0,0,0):
    //Multi: 121.259842519685:
    //Origin: (720,-30.0000000000001,0):
    //PISO: 1/4":

     

    ~'J'~

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Active Member
    MarcioCartacho
    Posts: 9
    Registered: ‎04-18-2012

    Re: I have difficulties in handling API AutoCAD.Net using Dynamic Blocks

    07-20-2012 05:43 AM in reply to: Hallex

    Hello,Hallex

     

    The example you sent me worked perfectly. Thank you!

    However, when I try to change: if (prop.PropertyName == "Block Table1") {prop.Value = 6;}

    generates an error: e.Mensagem: eInvalidInput,

    e.StackTrace: at Autodesk.AutoCAD.DatabaseServices.DynamicBlockReferenceProperty.set_Value (Object Value) at ClassLibrary1.Class1.GetProps ().

    I would like to change my Dynamic Block by setting the value of the "Block Table1"

     

    for example:

    if (prop.PropertyName == "Block Table1") {prop.Value = 6;}

     

    thanks for the help and attention!!

    Metso Minerals

    Márcio Lourenço Cartacho
    C.A.D application Developer
    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,334
    Registered: ‎10-08-2008

    Re: I have difficulties in handling API AutoCAD.Net using Dynamic Blocks

    07-20-2012 06:28 AM in reply to: MarcioCartacho

    I have never worked with BlockTable, but I will

    to try this way,

    Later,

     

    ~'J'~

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Active Member
    MarcioCartacho
    Posts: 9
    Registered: ‎04-18-2012

    Re: I have difficulties in handling API AutoCAD.Net using Dynamic Blocks

    07-20-2012 07:10 AM in reply to: Hallex

    Ok thank you very much. See this example that I found in LISP program. the program does exactly what I need, but I would like do in C##.NET program.

     

    ;(GetBlockValue "Block Table1" 2)
    (defun GetBlockValue (prop value)												       
    	(vl-load-com)												   	               
          	(setq block (entlast)) 	      											      	       
          	(vl-some 
    		(function (lambda ( _prop ) 
    			(if (eq prop (strcase (vla-get-propertyname _prop)))
    				(progn	
    					(vla-put-value _prop (vlax-make-variant value (vlax-variant-type (vla-get-value _prop))))
    					value
    				)
    			)
    		)
    	)
    	(vlax-invoke (vlax-ename->vla-object Block) 'GetDynamicBlockProperties))
    )

     

     

    Metso Minerals

    Márcio Lourenço Cartacho
    C.A.D application Developer
    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,334
    Registered: ‎10-08-2008

    Re: I have difficulties in handling API AutoCAD.Net using Dynamic Blocks

    07-20-2012 11:47 AM in reply to: MarcioCartacho

    Sorry this is out of my skills,

    I didn't know how to rich at Block Table rows

    using c#

     

    :smileyindifferent:

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Active Member
    MarcioCartacho
    Posts: 9
    Registered: ‎04-18-2012

    Re: I have difficulties in handling API AutoCAD.Net using Dynamic Blocks

    07-23-2012 03:35 AM in reply to: Hallex

    Hallex,

    Thanks for your attention.

    Metso Minerals

    Márcio Lourenço Cartacho
    C.A.D application Developer
    Please use plain text.
    ADN Support Specialist
    Marat.Mirgaleev
    Posts: 20
    Registered: ‎05-25-2011

    Re: I have difficulties in handling API AutoCAD.Net using Dynamic Blocks

    08-01-2012 10:47 AM in reply to: MarcioCartacho

    Márcio,

     

       I suspect the "Block Table1" property cannot be assigned with 6 (integer). Please, inspect its type in your code or in the debugger - prop.PropertyTypeCode, it is a value from this enumeration (described in the ObjectARX Reference Guide):

     

    enum DwgDataType {
      kDwgNull = 0,
      kDwgReal = 1,
      kDwgInt32 = 2,
      kDwgInt16 = 3,
      kDwgInt8 = 4,
      kDwgText = 5,
      kDwgBChunk = 6,
      kDwgHandle = 7,
      kDwgHardOwnershipId = 8,
      kDwgSoftOwnershipId = 9,
      kDwgHardPointerId = 10,
      kDwgSoftPointerId = 11,
      kDwg3Real = 12,
      kDwgInt64 = 13,
      kDwgNotRecognized = 19
    };



    Marat Mirgaleev
    Developer Technical Services
    Autodesk Developer Network
    Please use plain text.