Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

write a custom iProperty to an Autocad Block attribute- iLogic (title block)

andrew_canfield
Collaborator

write a custom iProperty to an Autocad Block attribute- iLogic (title block)

andrew_canfield
Collaborator
Collaborator

Hello

Searched  though a few posts by struggling to find code as iLogic.

Thinking of manually creating custom iproperties (in Inventor) & then write back the iproperties to the Acad Block attributes within the sheet title block (provided by customer) - {autocad uses array values??}

 

Attributes.png

 

Regards

 

Andrew

0 Likes
Reply
463 Views
6 Replies
Replies (6)

WCrihfield
Mentor
Mentor

Hi @andrew_canfield.  The good news is that there are methods in the Inventor API for doing this.  The AutoCADBlock object has two methods, one called "GetPromptTextValues", and one called "SetPromptTextValues".  These are the things that are called the 'Attributes' of the block in AutoCAD.  There are two variables involved in those two methods, and both variables are an array of String (String()).  On the Get side, you need to create the two variables of that type ahead of time, then supply them as input variables to the method, then run that method, then it fills in those two variables with the names and values.  On the Set side, you create these two variables ahead of time, fill them yourself, then put them in as input variables in the corresponding method and run it, and it puts those values in place for the names given.  If you still need more help writing the code for this, just let us know.

 

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

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

andrew_canfield
Collaborator
Collaborator

This is one way not to do it!... 

REF2.JPG

0 Likes

WCrihfield
Mentor
Mentor

Also, I forgot to mention that the AutoCADBlockDefinition object, which is what the AutoCADBlock object is based on, also has a method called "GetPromptTags".  With that you can get the list of 'Tags' and 'Prompts' from the block, without the Values.  And those Tags & Prompts are also both an array of String.

 

Whichever process you may use in your attempt to write new values to these, you pretty much need to know what specific order they are in when retrieved by code, because when you go to write the values, they are just put into an Array.  And they need to be put into that array in the same order as the Tags/Prompts are listed in their arrays, so that they correspond to the right ones.  What little I've messed with this process in the past, I do remember it not being a fun process.  This type of automation may only pay off if you have many drawings in which these tags & prompts are done exactly the same way and you plan to provide the same exact values each time.

 

Also...I believe that the Array objects you create when using the Set method need to be the correct size.  I'm pretty sure they need to be the same size (number of Items) as there are Tags/Prompts, so that there is one Item for each entry.  I'm pretty sure that you don't need to supply Values for each Item, but there needs to be a position in the Arrays for each item in the list.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

andrew_canfield
Collaborator
Collaborator
Thanks - it's a new project so they'll be a few drawings - will persevere.
0 Likes

andrew_canfield
Collaborator
Collaborator
Sub SetAttributesOnSheets()

  Dim oDrawDoc As DrawingDocument
  Set oDrawDoc = ThisApplication.ActiveDocument
    
  Dim Blockname As String
  Blockname = "Testblock"

  Dim oSheet As Sheet
  For Each oSheet In oDrawDoc.Sheets
    Dim oBlock As AutoCADBlock
    For Each oBlock In oSheet.AutoCADBlocks
      If oBlock.Name = Blockname Then
        Dim tagStrings() As String
        Dim textStrings() As String
    
        oBlock.GetPromptTextValues tagStrings, textStrings
    
        Dim i As Integer
        For i = LBound(tagStrings) To UBound(tagStrings)
          If tagStrings(i) = "TEXT1" Then
            textStrings(i) = "text1text"
          ElseIf tagStrings(i) = "TEXT2" Then
            textStrings(i) = "text2text"
          End If
        Next
    
        ' If multiple tag strings are the same then it will
        ' only set the value for the first one of them
        ' That's one of the reasons for this article
        ' to show how to do it using the AutoCAD API instead
        ' which seems to be working fine and can be used as
        ' a workaround
        oBlock.SetPromptTextValues tagStrings, textStrings
      End If
    Next
  Next
End Sub

This is the closest reference,

adndevblog 

I've found but ilogic doesn't use SET (just remove?) & it doesn't like SUB's (must be after SUB MAIN) - remove subs & then more errors ..

 

 

Can this be ported to iLogic?

 

 

0 Likes

WCrihfield
Mentor
Mentor

Here is a starter that you can work from.  It just does the first half of the job...getting the existing list of Prompts and Values, and how many of them there are.  From that point, you can reuse those two resulting array objects when you go to use them in the SetPromptTextValues method.  You would just have to either loop through those Values, or create a line for each value in the array, so you can set new values to them, before putting that array back into that second method.

 

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.", vbCritical, "iLogic")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	oSheet = oDDoc.ActiveSheet
	If oSheet.AutoCADBlocks.Count > 0 Then
		For Each oABlock As AutoCADBlock In oSheet.AutoCADBlocks
			If oABlock.Name = "A0" Then
				Dim oPromptTags() As String
				Dim oValues() As String
				oABlock.GetPromptTextValues(oPromptTags, oValues)
				oCount = oPromptTags.Length
				'just for feedback only
				oPrompt = InputListBox("", oPromptTags, "", "Prompt Tags", "List Of Prompt Tags")
				'just for feedback only
				oValue = InputListBox("", oValues, "", "Values", "List Of Values")
				
				'For i As Integer = 0 To UBound(oValues)
				'	oValues(i) = "something" & " something else"
				'Next
				'or
				oValues(0) = "first value"
				oValues(1) = "second value"
				'''
				'''
				oABlock.SetPromptTextValues(oPromptTags, oValues)
			End If
		Next
	End If
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes