.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get into the blocks and return block names and attributes

33 REPLIES 33
SOLVED
Reply
Message 1 of 34
danijel.radenkovic
17364 Views, 33 Replies

Get into the blocks and return block names and attributes

Hello,

Could someone help me with this? I would like to get all block with attributes in the opened drawing and to list the names of the blocks and their attribute's tags/values. So, firstly, I am trying to get the information about block names.

        'AutoCAD app
        Dim acadApp As AcadApplication
        acadApp = GetObject(, "AutoCAD.Application")

        'Active doc
        Dim dbxDoc As Object
        dbxDoc = acadApp.ActiveDocument
        acadApp.Visible = True

        Dim entity As Object

        'Catch blocks from the opened dwg
        For Each entity In dbxDoc.PaperSpace

            If TypeOf entity Is AcadBlockReference Then
                MsgBox(entity.GetType.Name)
            End If
        Next entity
    End Sub

Using code from the above the form is loaded but I am not getting the response about the block's name.

I am using AutoCAD 2017 and VB2015.

Many thanks!

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
33 REPLIES 33
Message 2 of 34

Since you are posting in AutoCAD .NET forum, Please to be aware that ".NET" as forum name is mainly meant for "AutoCAD .NET API" (naturally the programming language should be .NET language), and much less meant for using MS .NET in general. Thus the very first question a potential respondent to your post would possibly be: is there any particular reason for you to use AutoCAD COM API instead of .NET API? Then, the next possible question would be are you doing an out-porocess application (EXE app that automate AutoCAD instance) and why? Answers to these 2 questions would determine the usefulness of replies to your question.

 

Also, regarding to AutoCAD programming, we need to be very careful to use term "block", ofter, it is better to explicitly say "block definition" and "block reference". according to your question, do you want to list all names of defined blocks (block definitions) in the drawing (or limited to the block definitions that have Attribute defined in them)? Or, do you only want to list the blocks that visible (thus, block references) and with attribute references?

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 34


@norman.yuan wrote:

Since you are posting in AutoCAD .NET forum, Please to be aware that ".NET" as forum name is mainly meant for "AutoCAD .NET API" (naturally the programming language should be .NET language), and much less meant for using MS .NET in general. Thus the very first question a potential respondent to your post would possibly be: is there any particular reason for you to use AutoCAD COM API instead of .NET API? Then, the next possible question would be are you doing an out-porocess application (EXE app that automate AutoCAD instance) and why? Answers to these 2 questions would determine the usefulness of replies to your question.

 

Also, regarding to AutoCAD programming, we need to be very careful to use term "block", ofter, it is better to explicitly say "block definition" and "block reference". according to your question, do you want to list all names of defined blocks (block definitions) in the drawing (or limited to the block definitions that have Attribute defined in them)? Or, do you only want to list the blocks that visible (thus, block references) and with attribute references?


Hello,

Thank you for the reply.

1. Is there any particular reason for you to use AutoCAD COM API instead of .NET API?

I have found few similar posts about retriving "block definition" information and I have tried with the current code.

2. Are you doing an out-porocess application (EXE app that automate AutoCAD instance) and why?

The only thing that I would like to do is to get the attributes using vb.net application that I have created in the past. I would like to update my vb.net project with adding a possibility to iterate with AutoCAD 2017, so that is the reason why I am going via .exe application.

3. Do you want to list all names of defined blocks (block definitions) in the drawing (or limited to the block definitions that have Attribute defined in them)? Or, do you only want to list the blocks that visible (thus, block references) and with attribute references?

I would like to catch only block with the attributes, so I have tried firstly to list all blocks and after to set condition if current block definition has attributes then get the value of the attribute, if it has not then nothing.

Any help is very appreciated.

Danijel

 

 

 

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
Message 4 of 34

I concur with my colleague Norman - and as he has pointed out, i think it's best to use in-process solution rather than COM interop unless you have a good reason for using the latter.

 

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUI...

 

the above code will be inordinately helpful to you.

 

you can get the name of the block reference via the .Name property.

 

any probs pls ask.

 

(I would also add that since you're writing in VB.Net why not take the trouble right now to switch to c#. IMO it's easier and there are more code xamples on the forums etc. ) best wishes

Message 5 of 34

Hello to all,

Thank you very much for the help that you providing.

Few weeks ago, I have tried code that you provided but I had a problem to debug. The error that I have not solved was showed on the image bellow. I have tried to solve syntax problem with using potential fixes but I didn't have a success.

The reason why I have continued with vb.net instead of moving to C# is because I have almost finished project that has to be updated with new function (iterating with AutoCAD), but I have decided to move on C# after that.

image1.PNG

Any help is very appreciated.

Danijel

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
Message 6 of 34

I can still see 2 major issues:

 

1. You still use "block", even though I pointed out it is not clear what you want to list: block definition (with attribute definition), or block reference (with attribute reference). The result list would be different (unless the drawing is purged. that is, all block definitions in the drawing have block references created). In your previous reply you said "current block definition has attributes then get the value of the attribute". Mind you, attribute in block definition DOES NOT have value, attribute in block reference does. That is why you need to be clear: do you want to list block definitions, or do you want to list block references?

 

2. Since you are doing EXE, you can only use AutoCAD COM API. You CANNOT use AutoCAD .NET API. So, the code shown in your latest post does not help you at all.

 

Now, let's assume you still go with COM API. To list all block definitions that include attribute, you do (pseudo-code)

 

Dim ent As AcadEntity

Dim blk As AcadBlock

Dim hasAtt As Boolean

Dim count As Integer

For Each blk in ThisDrawing.Blocks

    hasAtt=False

    For Each ent In blk

        If TypeOf ent Is AcadAttribute Then

           MsgBox "Block """ & blk.Name & """ has attribute."

           count+count+1

           Exit For

        End If

    Next

Next

 

MsgBox count & " block definitions are found having attribute"

 

If you only want a block name list of VISIBLE blocks (block reference) that has attribute (attribute reference), then you can do:

 

Dim ss As AcadSelection

Dim ent As AcadEntity

Dim blk As AcadBlockReference

 

'' Create a selectionset to select everything in drawing (or with filter to select only "INSERT"

Set ss=ThisDrawing.SelectionSets.Add("test")

ss.Select acSelectionSetAll

For Each entin ss

  If TypeOf ent Is AcadBlockReference Then

    Set blk=ent

    If blk.HasAttributes Then

      MsgBox "Find block with attribute: """ & blk.EffectiveName & """."

    End If

  End If 

Next

 

Notice I use EffectiveName, in case the blockreference is a dynamic one. Of course, since there could be multiple block references to a block definition, the names obtained here could be duplicated. Also just to be aware: block reference can have attribute, or not have attribute regardless if the block definition it is based on has attribute defined in it or not (yes, it is unusual, but could happen), that is why I ask you to be clear: do you want to list name out of block definitions, or do you want to list names out of block references.

Norman Yuan

Drive CAD With Code

EESignature

Message 7 of 34

Hello

 

 

Then the easiest solution is to go to this site: http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=18162650 download the ObjectArx and Wizards. After you download the Wizards next time you go into visual studio create a new autocad template.

 

 

I created a screencast hope it helps:  http://autode.sk/2oj4ZQI

 

 

 

 

Message 8 of 34

I have downloaded ObjectARX 2017 Wizard  and AutoCAD 2017 DotNet Wizards and installed them. Templates are only visible if the .Net Framework 4.5 is chosen. In the past, I have installed for the Inventor and it works perfect as it is showed on the image bellow, even if the .NET Framework 4.6 is chosen. It is not a problem to switch my project to v4.5.

img.PNG

Your screencast helped me to understand possible ways of iterating with AutoCAD, so please correct me if I am wrong.

  1. Using AutoCAD .NET API=>you said ACAD has to be opened. Using NETLOAD, I am loading a plug-in (.dll file). By calling a command I am running a code.

In previous example "GettingAttributes" could be a command to run the code.

This is probably better way to iterate with AutoCAD but I would like to avoid typing of commands in AutoCAD. My idea is get all attribute values (see the image bellow) of the blocks in the opened drawing by clicking on the button on my form.

1.PNG

  1. Using AutoCAD COM API=> you said ACAD don't need to be opened. But my idea is to work with the opened drawing and I believe it is not a problem.

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
Message 9 of 34


@norman.yuan wrote:

I can still see 2 major issues:

 

1. You still use "block", even though I pointed out it is not clear what you want to list: block definition (with attribute definition), or block reference (with attribute reference). The result list would be different (unless the drawing is purged. that is, all block definitions in the drawing have block references created). In your previous reply you said "current block definition has attributes then get the value of the attribute". Mind you, attribute in block definition DOES NOT have value, attribute in block reference does. That is why you need to be clear: do you want to list block definitions, or do you want to list block references?

 

2. Since you are doing EXE, you can only use AutoCAD COM API. You CANNOT use AutoCAD .NET API. So, the code shown in your latest post does not help you at all.

 

Now, let's assume you still go with COM API. To list all block definitions that include attribute, you do (pseudo-code)

 

Dim ent As AcadEntity

Dim blk As AcadBlock

Dim hasAtt As Boolean

Dim count As Integer

For Each blk in ThisDrawing.Blocks

    hasAtt=False

    For Each ent In blk

        If TypeOf ent Is AcadAttribute Then

           MsgBox "Block """ & blk.Name & """ has attribute."

           count+count+1

           Exit For

        End If

    Next

Next

 

MsgBox count & " block definitions are found having attribute"

 

If you only want a block name list of VISIBLE blocks (block reference) that has attribute (attribute reference), then you can do:

 

Dim ss As AcadSelection

Dim ent As AcadEntity

Dim blk As AcadBlockReference

 

'' Create a selectionset to select everything in drawing (or with filter to select only "INSERT"

Set ss=ThisDrawing.SelectionSets.Add("test")

ss.Select acSelectionSetAll

For Each entin ss

  If TypeOf ent Is AcadBlockReference Then

    Set blk=ent

    If blk.HasAttributes Then

      MsgBox "Find block with attribute: """ & blk.EffectiveName & """."

    End If

  End If 

Next

 

Notice I use EffectiveName, in case the blockreference is a dynamic one. Of course, since there could be multiple block references to a block definition, the names obtained here could be duplicated. Also just to be aware: block reference can have attribute, or not have attribute regardless if the block definition it is based on has attribute defined in it or not (yes, it is unusual, but could happen), that is why I ask you to be clear: do you want to list name out of block definitions, or do you want to list names out of block references.


Hello @norman.yuan,

I am little bit confused about terms that you mentioned. But according to your sentence: "Mind you, attribute in block definition DOES NOT have value, attribute in block reference does." and also according to my drawing (attached file), it seems that I am actually looking for value in the attribute of block reference.

I have tried first part of code that you provided and I have got the names of all block definitions. But, as you said, if the drawing space is empty and if I run the code again, I will get the same answer. It's because the drawing is not purged.

Second part of your code looks like VBA code. I have adapted to vb2015 syntax.

 

Dim ss As AcadSelectionSet
        Dim ent As AcadEntity
        Dim blk As AcadBlockReference

        '' Create a selectionset to select everything in drawing (or with filter to select only "INSERT"
        ss = dbxDoc.SelectionSets.Add("test")

        ss.Select(AcSelect.acSelectionSetAll)

        For Each ent In ss
            If TypeOf ent Is AcadBlockReference Then
                blk = ent
                If blk.HasAttributes Then
                    MsgBox("Find block with attribute: " & blk.EffectiveName & ".")
                End If
            End If
        Next

Now, when I have got the list of all visible blocks, I would like to list the attributes. According to my drawing, should be:

 

TITLEBLOCK and the attributes are: Circle Block 1

TITLEBLOCK and the attributes are: Circle Block 2

RECTANG_BLOCK and the attributes are: Top_Left text and Bottom_Left text and Bottom_Right text and Top_Right text

At the end of the video, you can see that I have tried to run the code again but second debugging was not successful. Would you like to explain me why?

 

 

 

 

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
Message 10 of 34

Hi Danijel what my learned colleague Norman is referring to is this.

 

There are two separate concepts at play here. Block definitions. and block references. they are related but different.

 

Imagine I create a block called: "chair". The chair consists of the following lines. This is a block definition. It is saved somewhere in the Block table. Right now there are no chairs showing in my autocad drawing.

 

 

But what if I want to insert 200 chairs into my autocad drawing? Every chair is exactly the same. So rather than copy the chair 200 times what autocad does is something very smart - it creates 200 "block references". There is only one chair. This is stored in the block table. But there are 200 references to that chair. we save memory by doing this.

 

But not all block references are the same. some might have different attribute values. 

 

what you want i think is to get the attribute values of some block references which exist in your autocad drawing.

 

this code will help - but it's in c#. the concepts are the same:

 

public static string GetAV(ObjectId id, string attributeName) //pass in the blockreferenceID of the blockreference
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;

            string attributevalue = "";
             
            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {
                    BlockReference br = tr.GetObject(id, OpenMode.ForRead) as BlockReference;

                     if (br!= null)
                     {
                         AttributeCollection arColl = br.AttributeCollection;

                         if (arColl != null)
                         {

                             foreach (ObjectId arID in arColl)
                             {

                                 AttributeReference ar = tr.GetObject(arID, OpenMode.ForRead) as AttributeReference;

                                 if (ar.Tag == attributeName)
                                 {
                                     
                                     attributevalue = ar.TextString;
                                 }
                             }
                         } 
                     }
                 
             }
            return attributevalue;
        }

 

 

 

public static ObjectIdCollection GetBRids(string blockname)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;

            ObjectIdCollection blockReferenceIDs = new ObjectIdCollection();            

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

                foreach (ObjectId btrID in bt)
                {
                    BlockTableRecord btr = tr.GetObject(btrID, OpenMode.ForRead) as BlockTableRecord;

                    if (btr != null)
                    {
                        if ( btr.Name == blockname)
                        {
                            blockReferenceIDs = btr.GetBlockReferenceIds(true, true);
                        }
                    }
                }
            }

            return blockReferenceIDs;
        }

 

that will give you some basic ideas of the concepts involved.

 

please review what Norman has written.

 

Message 11 of 34

No, that is COM API code. use the .net API code to get your attribute values.

Message 12 of 34

Hello @BKSpurgeon,

I am totally confused by your last post.

I have translated code that you provided to import it in VisualBasic but there are few lines that are not correctly defined. I am not using C# and I have  problem to translate code to VB correctly. Problematic code is red colored.

 

    Public Shared Function GetAV(ByVal id As ObjectId, ByVal attributeName As String) As String
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim db As Database = doc.Database
        Dim attributevalue As String = ""
        Dim tr As Transaction = doc.TransactionManager.StartTransaction
        Dim br As BlockReference = CType(tr.GetObject(id, OpenMode.ForRead),BlockReference)
        If (Not (br) Is Nothing) Then
            Dim arColl As AttributeCollection = br.AttributeCollection
            If (Not (arColl) Is Nothing) Then
                For Each arID As ObjectId In arColl
                    Dim ar As AttributeReference = CType(tr.GetObject(arID, OpenMode.ForRead),AttributeReference)
                    If (ar.Tag = attributeName) Then
                        attributevalue = ar.TextString
                    End If
                    
                Next
            End If
            
        End If
        
        Return attributevalue
    End Function
Public Shared Function GetBRids(ByVal blockname As String) As ObjectIdCollection
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim db As Database = doc.Database
        Dim blockReferenceIDs As ObjectIdCollection = New ObjectIdCollection
        Dim tr As Transaction = db.TransactionManager.StartTransaction
        Dim bt As BlockTable = CType(tr.GetObject(db.BlockTableId, OpenMode.ForRead),BlockTable)
        For Each btrID As ObjectId In bt
            Dim btr As BlockTableRecord = CType(tr.GetObject(btrID, OpenMode.ForRead),BlockTableRecord)
            If (Not (btr) Is Nothing) Then
                If (btr.Name = blockname) Then
                    blockReferenceIDs = btr.GetBlockReferenceIds(true, true)
                End If
                
            End If
            
        Next
        Return blockReferenceIDs
    End Function

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
Message 13 of 34

that's unusual, 

 

in fact all we need is the database. not the editor. 

 

so you can get rid of those lines and replace them with:

 

Dim db As Autodesk.AutoCAD.DatabaseServices.Database
    db = Application.DocumentManager.MdiActiveDocument.Database

 

 

 

rgds

 

 

Message 14 of 34
_gile
in reply to: danijel.radenkovic

@danijel.radenkovic,

The problem is not between laguages (VB vs C#) which are quite closed as you can see, but between the used API.

 

It looks like you want/need to use the COM/ActiveX API (referencing Autodesk.AutoCAD.Interop.dll and Autodesk.AutoCAD.Interop.Common.dll libraries) and @BKSpurgeon gave you a reply using the .NET API (which uses the accoremgd.dll, acdbmgd.dll and acmgd.dll libraries).

 

Please, attentively read @norman.yuan's replies and also these topics from the .NET Developer's Guide : COM Interoperability (.NET) and Out-of-Process Versus In-Process (.NET).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 15 of 34
danijel.radenkovic
in reply to: _gile

Hello @_gile,

Now I am totally confused by all pieces of codes on this topic. Let's back to the only solution that worked last time. Here is a code which gives me the names of the block in the opened drawing. Please see attached video. Now I would like to get the attributes. How?

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports AutoCAD
'Imports Autodesk.AutoCAD.DatabaseServices
'Imports Autodesk.AutoCAD.Geometry
'Imports Autodesk.AutoCAD.EditorInput

Imports Microsoft.Office
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Word
Imports System.IO


Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        '##########################################################################################################################

        'AutoCAD app
        Dim acadApp As AcadApplication
        acadApp = GetObject(, "AutoCAD.Application")

        'Active doc
        Dim dbxDoc As Object
        dbxDoc = acadApp.ActiveDocument
        acadApp.Visible = True

        Dim ss As AcadSelectionSet
        Dim ent As AcadEntity
        Dim blk As AcadBlockReference

        '' Create a selectionset to select everything in drawing (or with filter to select only "INSERT"
        ss = dbxDoc.SelectionSets.Add("test")

        ss.Select(AcSelect.acSelectionSetAll)

        For Each ent In ss
            If TypeOf ent Is AcadBlockReference Then
                blk = ent
                If blk.HasAttributes Then
                    MsgBox("Find block with attribute: " & blk.EffectiveName & ".")
                End If
            End If
        Next
End Sub
End Class
Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
Message 16 of 34

You probably missed something from my previous replies. Based on what you show here, let me try one more time:

 

1. You are doing an EXE application to automate AutoCAD (get block information from a drawing opened in AutoCAD. Is that correct? If not, stop reading. We are done.

 

2. As I said previously, in EXE project, you CANNOT USE AutoCAD .NET API. If you added AutoCAD nET API to your EXE project, it would like not start at all (you would argue your EXE app did run with AutoCAD .NET API added as references as your video shows. Read on.)

 

3. As I said, in your project shown in the video, you did add Acad .NET API references and the app runs. Well, you are lucky enough that the EXE app only has very simple code that only uses COM API. If the code touches AutoCAD API, your EXE will crash.

 

4. While BKSpurgeon recommended using AutoCAD .NET API, the condition is you do AutoCAD add-in, not EXE app. Otherwise, anything related to AutoCAD .NET API does not apply to your case.

 

5. You still do not make it clear you want to list all the names of block definitions (with attribute in it), or names of block references that has attribute. Let assume you do know the difference of block definition and block reference, then according to your short "working" code, what you need is name list of block references. Since you mentioned the code ran but get nothing back. That means the drawing may have many block defined in it, but does not have block references (with attribute) are inserted into the drawing, thus no block name is collected. anyway, in my previous reply I have showed the code of getting name list either from block definitions, or from block references. You need to get anything related to AutoCAD .NET API for your EXE app (even I have said the external EXE app is not a good solution in most cases).

Norman Yuan

Drive CAD With Code

EESignature

Message 17 of 34

 

Regarding the ambiguous reference to Application ...

 

I'd guess it's because you will have a Microsoft Office Application and an AutoCAD Application referenced.

Try using a fully qualified namespace path in your assignments where there may be ambiguity.

 

Regards,

 

 


// Called Kerry in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 18 of 34

 

norman.yuan wrote:

You probably missed something from my previous replies. Based on what you show here, let me try one more time:

 

1. You are doing an EXE application to automate AutoCAD (get block information from a drawing opened in AutoCAD. Is that correct? If not, stop reading. We are done.

Yes that's correct. I am trying to iterate with AutoCAD using my exe application.

 

2. As I said previously, in EXE project, you CANNOT USE AutoCAD .NET API. If you added AutoCAD nET API to your EXE project, it would like not start at all (you would argue your EXE app did run with AutoCAD .NET API added as references as your video shows. Read on.)

Clear.

 

3. As I said, in your project shown in the video, you did add Acad .NET API references and the app runs. Well, you are lucky enough that the EXE app only has very simple code that only uses COM API. If the code touches AutoCAD API, your EXE will crash.

So adding the refferences (AcCoreMgd.dll, AcMgd.dll, AcDbMgd.dll) are reserved just for AutoCAD .NET API (creating .dll which will be loaded using netload and running by command in AutoCAD). Am I right? This is not something that I want, I want to avoid netload loading of .dll. I want to iterate with AutoCAD directly from my .exe application.

4. While BKSpurgeon recommended using AutoCAD .NET API, the condition is you do AutoCAD add-in, not EXE app. Otherwise, anything related to AutoCAD .NET API does not apply to your case.

 

5. You still do not make it clear you want to list all the names of block definitions (with attribute in it), or names of block references that has attribute. Let assume you do know the difference of block definition and block reference, then according to your short "working" code, what you need is name list of block references. Since you mentioned the code ran but get nothing back. That means the drawing may have many block defined in it, but does not have block references (with attribute) are inserted into the drawing, thus no block name is collected. anyway, in my previous reply I have showed the code of getting name list either from block definitions, or from block references. You need to get anything related to AutoCAD .NET API for your EXE app (even I have said the external EXE app is not a good solution in most cases).

I am still confused about the differences between block definition and block refference. Would you like to open please the drawing in the attachment and check the created blocks. What I want is this:

TITLEBLOCK and the attributes are: Circle Block 1

TITLEBLOCK and the attributes are: Circle Block 2

RECTANG_BLOCK and the attributes are: Top_Left text and Bottom_Left text and Bottom_Right text and Top_Right text

This lines from the above are return that I want to get in msgbox, so are they type of block references (which have the attributes) or not?



 

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
Message 19 of 34
_gile
in reply to: danijel.radenkovic

If I don't misundertand what you're trying to do, for each selected attributed block, you have to iterate through its attribute collection.

 

Have a look at the GetAttributes COM/ActiveX method.

 

Not sure about VB syntax.

 

        For Each ent In ss
            If TypeOf ent Is AcadBlockReference Then
                blk = ent
                If blk.HasAttributes Then
		    Dim text As String = "Find block with attribute: " & blk.EffectiveName & "."
		    For Each att As AttributeReference In blk.GetAttributes()
			text = text & vbCr & att.TagString & ": " & att.TextString
		    Next
                    MsgBox(text)
                End If
            End If
        Next


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 20 of 34

My apologies seems that i have confused you. anything that my learned colleagues norman and Gilles is very good to read. seeing you dont want to netload use the COM API so the above c# code i provided (which you translated) needs to be scrapped. 

 

i've written above a basic summary of the difference between a block definition and a block reference.

 

here is something further which might help.

 

difference between block reference and definition

 

Imagine you wrote a really long book about the meaning of life - and that you wanted to distribute it to all your friends. Rather than carry around 10 paper copies of the book (which is 5000 pages long) in your bag - remember carrying all that weight is difficult and it's heavy - it's much more efficient for you to have simply one copy of your essay online and to direct people to go to read your essay online rather than giving them a physical paper copy. that way there is only one definition of your book but many references to your book.

 

Supposing you wanted your mother to read the book but you wanted to change is slightly so that she would understand it better? No problems. Use the same definition, but add any changes to the web link reference that you gave her. Most of the book remains the same. so you still refer to the online version, but the weblink shows a modified version of the book.

 

think of it along those lines and i hope it helps.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report