Assign Custom Properties to a Title Block Drawing Using iLogic

Assign Custom Properties to a Title Block Drawing Using iLogic

fsdolphin
Collaborator Collaborator
1,989 Views
8 Replies
Message 1 of 9

Assign Custom Properties to a Title Block Drawing Using iLogic

fsdolphin
Collaborator
Collaborator

Hi, 

 

In my model, I have a custom property called `Metal Rules` and In the drawing, I'm assigning this to the Material field.  Doing this manually is not a problem since I modified the template and it takes care of any new drawing created, the issue is with existing drawing not having this custom property assigned.

 

How can I assign custom properties to a Title Block in a drawing using iLogic?

 

Here is ultimately how I want to assign the custom property but using iLogic.

 

Before running iLogic...

Custom Property in Drawing Empty.png

 

After running iLogic...

Custom Property in Drawing.png

 

Incomplete Code:

Sub Main()
	doc = ThisDoc.Document
	If (doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject) Then 
		' Code for property assigment would go here...
		MessageBox.Show("Properties have been updatated!") 
	Else 
               MessageBox.Show("Oops, this is NOT a drawing document, nice try!","Information",MessageBoxButtons.OK , MessageBoxIcon.Information)
		Return
	End If
End Sub 

 

FYI - Title Block Name: Model Properties Title Block

 

Thanks

 

0 Likes
Accepted solutions (1)
1,990 Views
8 Replies
Replies (8)
Message 2 of 9

garrettfulghum
Contributor
Contributor

Im not completely sure if this is what you are looking for but you can use XML Parameters when you send your ilogic command to update the title block:

 

Parameter <Parameter>

The parameter tag defines that the value of a parameter is to be used in the text string.

 

Example:

Here is a sample (this assumes that "C:\temp\test.ipt" is a document referenced by the drawing and contains a model parameter named "d0"). The ComponentIdentifier tag is not required if working within part sketches.

"<Parameter ComponentIdentifier='C:\temp\test.ipt' Name='d0' Precision='2' ></Parameter>"

 

This would be the string you would use to update the title block with the XML identifier 'Parameter'

 

If you would like the complete list of XML Parameters search 'XML Tags for FormattedText' in the API help.

 

 

Message 3 of 9

fsdolphin
Collaborator
Collaborator

I'm not sure I understand what you're suggesting, sorry.

0 Likes
Message 4 of 9

rhasell
Advisor
Advisor
Accepted solution

Hi

I have looked at this as well, and to date, I do not have a solution, so I will follow your thread.

But

What you can try, instead of adding an entry into the titleblock, why don't you use iLogic to replace the entire title block with the one from the template?

 

Snippet:

Replace your template name and put the titleblock name in the correct place.

ThisDrawing.ResourceFileName = "d:\data\templates\template.idw"
ThisDrawing.KeepExtraResources = False
			ActiveSheet.TitleBlock = "TitleBlockName"
Reg
2026.1
Message 5 of 9

garrettfulghum
Contributor
Contributor

I managed to whip up an example for you,

Just to confirm, all you want is an Ilogic code to edit the active title block and replace a field with a model/document property? If so, the following works great for me:

 

        Dim InvApp As Inventor.Application
        InvApp = Marshal.GetActiveObject("Inventor.Application")
        Dim oDoc = InvApp.ActiveDocument

        If (oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject) Then
            Dim objDrawDoc As DrawingDocument = CType(InvApp.ActiveDocument, DrawingDocument)

            'The following gets the active title block in the specified ACTIVE sheet.
            Dim TitleBlock As TitleBlock = objDrawDoc.ActiveSheet.TitleBlock
            Dim objTitleBlkDef As TitleBlockDefinition = TitleBlock.Definition

            ' If we are here we have the title block of interest.
            ' Get the title block sketch and set it active
            Dim objDrwSketch As DrawingSketch = Nothing
            objTitleBlkDef.Edit(objDrwSketch)

            'Get the collection of textboes in the TitleBlockDefinition
            Dim colTextBoxes As TextBoxes = objDrwSketch.TextBoxes


            'Summary Information, {F29F85E0-40FF9-1068-AB91-08002B27B3D9}
            'Document Summary Information, {D5CDD502-20000000000C-101B-9397-08002B2CF9AE}
            'Design Tracking Properties, {328530F0F-3444-11D1-9E93-0060B03C1CA6}
            'User Defined Properties(Custom Properties), {D5CDD505-20000000000C-101B-9397-08002B2CF9AE} The property ids is in increasing order as they are in the iprop window

            For Each objTextBox As Inventor.TextBox In colTextBoxes
                'Scan all text boxes in the active title block definition until we come accross the text box named "TITLE"

                If objTextBox.Text = "TITLE" Then

                    'The following line using xml parameters edits the title block definition and replaces the text bob "TITLE" with the <Description> model property.
                    'Property ids can be found using the object browser

                    'I dont have your <METAL> property but you can replace it with your id to get the same affect.
                    objTextBox.FormattedText = "<Property Document='model' FormatID='{32853F0F-3444-11d1-9E93-0060B03C1CA6}' PropertyID='29' />"
                    Exit For

                End If

            Next

            objTitleBlkDef.ExitEdit(True)
            'Close and save changes to active titleblock
        Else
            MessageBox.Show("Oops, this is NOT a drawing document, nice try!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
        Return True
    End Function

Note I wrote this is VB.net (External Console app) but with very little changes with grabbing the InvApp, you can put this in ilogic.

 

Before Running:

Before.PNG

After running rule:

 

After.PNG

0 Likes
Message 6 of 9

fsdolphin
Collaborator
Collaborator

@rhasell  Your solution worked. Thanks a lot!

Message 7 of 9

fsdolphin
Collaborator
Collaborator

@rhasell  One last question.

 

Your solution successfully copies the TitleBlock from the template to the drawing, adds it to the `Title Blocks` folder inside the `Drawing Resource` folder and replaces the block for the active sheet. Do you know how to do the replacement in all sheets, not just the active one?

 

0 Likes
Message 8 of 9

rhasell
Advisor
Advisor

Hi

Manged to make something from the help files. Give this a try, it worked for me.

"Copying a title block definition API Sample"

 

ThisDrawing.ResourceFileName = "d:\data\templates\template.idw"
ThisDrawing.KeepExtraResources = False
Dim oSheets As Sheets
oDoc = ThisDoc.Document
Dim oSheet As Sheet
	For Each oSheet In oDoc.Sheets
        oSheet.Activate
			ActiveSheet.TitleBlock = "TitleBlockName"
			Next
Reg
2026.1
Message 9 of 9

fsdolphin
Collaborator
Collaborator

That worked, thanks a lot!