editing attribute set of an imported AutoCAD Block

editing attribute set of an imported AutoCAD Block

mostafamahmoudseddek94
Advocate Advocate
864 Views
6 Replies
Message 1 of 7

editing attribute set of an imported AutoCAD Block

mostafamahmoudseddek94
Advocate
Advocate

Hi

I imported the company Title Block to my Drawing file inside Inventor. It is an AutoCAD title Block that contains Attributes to be filled as shown. I can easily fill those attributes in inventor just by clicking the right click and select " Edit Attribute Set" command.

mostafamahmoudseddek94_0-1625994612922.png

I want to add these values automatically by inventor API. Unfortunately, My code shows me that it counted 0 Attribute set for this block .

Sub TitleBlockAttributes()
' Set a reference to the drawing document.
' This assumes a drawing document is active.
    
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
       
' ' Set a reference to the drawing Sheet NO.1

    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.Sheets.Item(1)
' Obtain a reference to the desired AutoCAD block definition.

    Dim oBlockDef As AutoCADBlockDefinition
    Set oBlockDef = oDrawDoc.AutoCADBlockDefinitions.Item("REDECAM-TITOLO-TAVOLA")
    MsgBox (oBlockDef.AttributeSets.Count)

End Sub

 Thanks For all

0 Likes
Accepted solutions (1)
865 Views
6 Replies
Replies (6)
Message 2 of 7

SharkDesign
Mentor
Mentor

What attributes do you want?

The standard way of doing it is to pull the iproperties directly into the title block. I'm assuming you want something more complicated than this if you're using iLogic

  Inventor Certified Professional
0 Likes
Message 3 of 7

SharkDesign
Mentor
Mentor

If you want to use code, the customisation forum is also a better place to post. 

https://forums.autodesk.com/t5/inventor-customization/bd-p/120

 

 

  Inventor Certified Professional
0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

Once you copy an AutoCADBlock or AutoCADBlockDefinition from AutoCAD to Inventor, then Inventor thinks of those 'attributes' in this case as it would 'prompted entries', instead of Inventor's idea of Attributes.  See the following links for more info on accessing those prompted entries by code.

AutoCADBlockDefinition.GetPromptTags Method

AutoCADBlock.GetPromptTextValues Method 

AutoCADBlock.SetPromptTextValues Method 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

mostafamahmoudseddek94
Advocate
Advocate

Hi, I am trying to use these methods but I do not know how to do it, is it possible to show me a simple code.

Thanks

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor
Accepted solution

I haven't tested this yet, because I don't have any AutoCAD blocks to import with prompted entries right now, but this code should get you pretty close to what you need.  I noticed that your original code seemed to be in VBA, instead of iLogic, so I stuck with that format for this code.  Also, here is another related Sample VBA code I found.  I'm using the method from the first link in that last post within this code, but the other two methods are more for working with an already existing AutoCADBlock object (an instance you have placed onto your sheet, not the definition).  I assumed that since you are wanting the code to fill in these prompted entries, that you are also placing the block onto the sheet for the first time also in this process.  If that is not the case, and you want to use this code after you have already placed the block, just let me know, because the code will have to change a bit for that task.

There is a place within the code where I started to fill in Values to match your screen shot, but didn't finish because it's a long list.  You will need to finish filling in any values you want.  The array variable itself must be the correct size for how many input values are needed, but I don't think you need to provide a value in each position of the array for it to work.

Here's what I've got for you right now:

Sub TitleBlockAttributes()
' Set a reference to the drawing document.
' This assumes a drawing document is active.
    
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
       
' ' Set a reference to the drawing Sheet NO.1

    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.Sheets.Item(1)
' Obtain a reference to the desired AutoCAD block definition.

    Dim oBlockDef As AutoCADBlockDefinition
    Set oBlockDef = oDrawDoc.AutoCADBlockDefinitions.Item("REDECAM-TITOLO-TAVOLA")
	'to use GetPromptTags, you must first create the empty variable(s) of the right type it needs
	'then supply those variables to the method, then it will assign their values
	Dim oTags() As String
	Dim oPrompts() As String
	Call oBlockDef.GetPromptTags(oTags, oPrompts)
	
	'create Array of strings to hold your input Values, in correct order
	Dim oPromptStrings()
	'resize the Array to the number of Tags/Prompts retrieved
	ReDim oPromptStrings(oTags.Length - 1)
	'
	oPromptStrings(0) = "1_0"
	oPromptStrings(1) = "___"
	oPromptStrings(3) = "C1aappp-nn"
	oPromptStrings(4) = "app"
	oPromptStrings(5) = "gr"
	'............................
	'<<<< FINISH FILLING THIS PART IN >>>>
	'and so on until you have provided all values you want
	
	'create position point for where to place the block
	Dim oTG As TransientGeometry
	Set oTG = ThisApplication.TransientGeometry
	Dim oPosition As Point2d
	Set oPosition = oTG.CreatePoint2d(0, 0)
	
	'create a block instance from the block definition, and place it onto your sheet
	'and provide all these variable's we've created as the input variables to this method
	Dim oABlock As AutoCADBlock
	Set oABlock = oSheet.AutoCADBlocks.Add(oBlockDef, oPosition, 0, 1, oPromptStrings, False)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 7

mostafamahmoudseddek94
Advocate
Advocate

Thanks for your wonderful reply. Indeed, it got me what I wanted to do.

0 Likes