VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Converting AttributeDefinition objects to Text objects on Same Layer

1 REPLY 1
Reply
Message 1 of 2
Fmissem
481 Views, 1 Reply

Converting AttributeDefinition objects to Text objects on Same Layer

 

Hello All,

 

I'm having an issue, and I'm hoping someone can give me a push in the right direction.

 

A little background first....

 

I have several .dwg files that I use as templates. I run find and replace VBA routines on the template .dwg files, ie find $Flavor$ and replace it with "Grape", and then I save the .dwg to another directory with a new name. 

 

These VBA routines work well for acdbText and acdbMText objects, but I have a bunch of AcdbAttributeDefinition objects in the .dwg templates as well.

 

After much research about the AutoCAD object model (I'm mostly a Microsoft Access VBA programmer), I have come to understand that these AcdbAttributeDefinition objects are actually "remnants" of a block that no longer exists in the drawing. Please, correct me if I'm misunderstanding this concept.

 

Anyway, I'd like to convert all of these orphaned AcdbAttributeDefinition objects to acdbText objects in the templates and then delete the AcdbAttributeDefinition objects. I have some code that does just that.

 

However, the issue that I am having with the code is that the newly created acdbText objects are not on the same layer that the original AcdbAttributeDefinition objects were on. I don't know the syntax to identify what layer the AcdbAttributeDefinition object is on or how to specify what layer on which the acdbText object is created.

 

Can anybody tell me how to keep the acdbText objects on the same layers as the original AcdbAttributeDefinition objects during the conversion and deletion process?

 

Here is the code I am using currently:

Sub AttConvert(dwg as string)

Dim oDocument as AcadDocument
Dim ent as AcadEntity
Dim aa as object

set oDocument = Documents.open(dwg)

 For Each ent In oDocument.ModelSpace
	 If ent.ObjectName = "AcDbAttributeDefinition" Then
	' DO SOMETHING TO IDENTIFY WHAT LAYER THE ACDBATTRIBUTEDEFINITION OBJECT IS ON
' DO SOMETHING TO SPECIFY THAT THAT IS THE LAYER TO CREATE THE ACDBTEXT OBJECT ON Set aa = ThisDrawing.ModelSpace.AddText(ent.TagString, ent.InsertionPoint, ent.Height) End If Next ent For Each ent In ThisDrawing.ModelSpace If ent.ObjectName = "AcDbAttributeDefinition" Then ent.Delete End If Next ent End Sub

 

 

Many Thanks,

Big D

1 REPLY 1
Message 2 of 2
truss_85
in reply to: Fmissem

use this

 

    aa.Layer = ent.Layer
    aa.color = ent.color

 

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

Post to forums  

”Boost