Author Topic: ACAD COM Interop, accessing attributes  (Read 5007 times)

0 Members and 1 Guest are viewing this topic.

Ramanujan

  • Guest
ACAD COM Interop, accessing attributes
« on: June 24, 2010, 11:59:27 PM »
Hi,

I am creating a VB . NET 2005 win32 console application to extract the tag name, text and prompt attributes of a block from a ACAD 2009 drawing. I cannot use SendCommand as it pops up the GUI when executing from batch mode.

When using COM Interop, I am not able to extract the prompt attribute, which I guess would otherwise be possible through the AttributeDefinition object (in-process - AttributeDefinition.prompt). I am using AcadAttributeReference to get tag and text properties.

How can I extract the prompt attribute value?

Thanks

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: ACAD COM Interop, accessing attributes
« Reply #1 on: June 25, 2010, 03:27:35 AM »
AttributeDefinition will give you the prompt.
Me

Ramanujan

  • Guest
Re: ACAD COM Interop, accessing attributes
« Reply #2 on: June 25, 2010, 01:29:39 PM »
Thanks for the reply. That is what I stated in my post. AttributeDefinition.prompt will return the value!

"When using COM Interop, I am not able to extract the prompt attribute, which I guess would otherwise be possible through the AttributeDefinition object (in-process - AttributeDefinition.prompt). I am using AcadAttributeReference to get tag and text properties."
I am creating a standalone executable which will run in batch mode. AttributeDefinition is accessible through the Autodesk.AutoCAD.DatabaseServices namespace.

The moment I declare something like this "Dim oAcDef As AttributeDefinition", the code fails to execute. I get the following error message :

"Additional information: A procedure imported by 'acdbmgd, Version=17.2.0.0, Culture=neutral, PublicKeyToken=null' could not be loaded."

Am I doing something wrong here?

Thanks

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: ACAD COM Interop, accessing attributes
« Reply #3 on: June 25, 2010, 01:58:41 PM »

Am I doing something wrong here?


As members of this forum are not, to the best of my knowledge, mind-readers, I don't know. You would need to post your code for me, at the least, to make a better judgement.

Also, what version of AutoCAD, Visual Studio (if any) and the .NET Framework are you using or targeting? As well, what are your goals for this program ie. what do you want it do specifically?
Me

Ramanujan

  • Guest
Re: ACAD COM Interop, accessing attributes
« Reply #4 on: June 25, 2010, 02:59:02 PM »
Hi,

Thanks for the reply.

I have attached a text file which has the code.

I have mentioned the details requested (.net & ACAD) in my first post. However, I am making it clear with the foll. lines:

Version of ACAD : 2009

Objective : To Create an executable (.exe file) which runs from the command prompt (No ACAD GUI, user triggers the exe to extract reports), creates the AcadApplication object, opens a drawing, reads the blocks, gets tag, string and prompt values, write this to a notepad file and sends back a return code. (There is no GUI here, runs in a silent mode. If I create a dll & use SendCommand, the GUI pops up)

Version of .NET used : .NET 2005 (MS .NET Framework 2.0)

Problem : I am able to extract the tag & text attributes. However, I am yet to figure out how to extract the 'prompt' value.

Hope this is sufficient information. Please let me know if any other inputs are required.

Thanks in advance for sparing your precious time to help out a mosquito!

Regards



Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: ACAD COM Interop, accessing attributes
« Reply #5 on: June 25, 2010, 03:56:07 PM »
Actually, you didn't make it clear in your first post regarding version of AutoCAD - you said you were opening a 2009 drawing - nothing more.

OK, I'll answer your original question first:

To get the Attribute Definition, from your Block reference, you need to get the Block Definition using the name to index the Blocks Collection from memory. Once you have that, you can troop through the entities in it to search for Attribute Definition objects (compare the tags) then do whatever you need to do.

I have to ask though, is there any specific reason you are using an out of process activex client to control AutoCAD? It is far slower than using an in-process dll ie. a .NET dll.

You can have a look at this for a batch processing harness that doesn't load each drawing graphically and is very fast.
Me

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7050
  • AKA Daniel
Re: ACAD COM Interop, accessing attributes
« Reply #6 on: June 25, 2010, 05:39:14 PM »
You're trying to use arx managed wrappers in your out of process code, you can't do this.
remove all references to acdbmgd and the like, then reference the com interopts. Then you can get the PromptString property of AcadAttribute

example

Code: [Select]
      ...
      AcadDocument doc = app.ActiveDocument;
      foreach (AcadBlock block in doc.Blocks)
      {
        foreach (AcadEntity ent in block)
        {
          AcadAttribute att = ent as AcadAttribute;
          if (att != null)
          {
            doc.Utility.Prompt("\n" +
                               att.TextString + "," +
                               att.TagString + "," +
                               att.PromptString);
          }
        }
      }

Ramanujan

  • Guest
Re: ACAD COM Interop, accessing attributes
« Reply #7 on: June 26, 2010, 01:16:46 AM »
Hi,

Daniel, You rock! Thanks a ton.
I have attached the working code (VB.NET).

Glenn, Thanks for the pointers. I haven't tried your method as Daniel's post had a very straight forward approach.
I will definitely work with your inputs and post that code as well. The batch is scheduled to run as a cron job. That's why, I am using the out of process method.

Thanks & Regards


Ramanujan

  • Guest
Re: ACAD COM Interop, accessing attributes
« Reply #8 on: June 26, 2010, 05:24:48 AM »
Hi,

For some reason, AcadAttribute.TextString doesn't return the correct value. So to extract the text I used AcadAttributeReference. Here is the code:


            Dim objAcAppCom As AcadApplication
            Dim objDwg As AcadDocument
            Dim objEntity As AcadEntity
            Dim objAtt1 As AcadAttribute
            Dim objBlock As AcadBlock
            Dim objFile As System.IO.File
            Dim objWrite As System.IO.StreamWriter
            Dim objBlockRef As AcadBlockReference
            Dim objAtt As AcadAttributeReference
            ............
            ............
            For Each objBlock In objDwg.Blocks
                For Each objEntity In objBlock
                    If objEntity.ObjectName.ToString = "AcDbBlockReference" Then
                        objBlockRef = objEntity
                        vAtts = objBlockRef.GetAttributes
                        For i = 0 To UBound(vAtts)
                            objAtt = vAtts(i)
                            console.writeline(objAtt.TextString)
                        Next
                    End If
                Next
            Next



Thanks again for all the help.

Regards