Link Properties to Drawing Text via api

Link Properties to Drawing Text via api

dg2405
Advocate Advocate
930 Views
5 Replies
Message 1 of 6

Link Properties to Drawing Text via api

dg2405
Advocate
Advocate

Hello,

is there a way to link propeties to Drawing textbox link in following picture:

Unbenannt.png

0 Likes
Accepted solutions (2)
931 Views
5 Replies
Replies (5)
Message 2 of 6

HideoYamada
Advisor
Advisor

Hello dg2405,

 

Do you want to add a <Filename> property to the end of the view label?

 

This code shows FormattedText of 1st (= base) view and copy it to the 2nd view label.

 

Sub test1()
    Dim drwDoc As DrawingDocument
    Set drwDoc = ThisApplication.ActiveDocument
    Dim activeSheet As Sheet
    Set activeSheet = drwDoc.activeSheet
    
    Debug.Print activeSheet.DrawingViews(1).Label.FormattedText

    MsgBox "FormattedText of the 1st view label is " & vbCr & activeSheet.DrawingViews(1).Label.FormattedText

    ' Copy Label format to the 2nd view.
    activeSheet.DrawingViews(2).Label.FormattedText = activeSheet.DrawingViews(1).Label.FormattedText
End Sub

 

 

If you want to access GeneralNote, this code will help you.

 

Sub test2()
    Dim drwDoc As DrawingDocument
    Set drwDoc = ThisApplication.ActiveDocument
    Dim activeSheet As Sheet
    Set activeSheet = drwDoc.activeSheet
    
    Dim gNote As GeneralNote
    Set gNote = activeSheet.DrawingNotes.GeneralNotes(1)
    MsgBox "Original FormattedText is " & vbCr & gNote.FormattedText
    
    ' Create and copy general note.
    Dim location As Point2d
    Set location = ThisApplication.TransientGeometry.CreatePoint2d(5, 5)
    activeSheet.DrawingNotes.GeneralNotes.AddFitted location, gNote.FormattedText
End Sub

 

 

The format of "FormattedText" is writen in the page XML Tags for FormattedText of API Help.

You can write it from scratch, but it's easy to write a template using Inventor UI and then copy the content of FormattedText into your code.

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 3 of 6

dg2405
Advocate
Advocate

Yes i want to add a e.g. <Filename> property to the end of the view label. Is this possible?

0 Likes
Message 4 of 6

HideoYamada
Advisor
Advisor
Accepted solution

Hello dg2405,

 

Default FormattedText of view label is :

<DrawingViewName/> ( <DrawingViewScale/> )

Adding a filename property to the end of the label cause :

<DrawingViewName/> ( <DrawingViewScale/> )<Br/><DerivedProperty DerivedID='29700'>FILENAME</DerivedProperty>

The number of DerivedID is a member of DerivedPropertyTypeEnum and 29700 is kDerivedDrawingFilename.

 

As a result, this code will add a filename property to all of views.

Sub test3()
    Dim drwDoc As DrawingDocument
    Set drwDoc = ThisApplication.ActiveDocument
    Dim activeSheet As Sheet
    Set activeSheet = drwDoc.activeSheet
    Dim dView As DrawingView
    
    For Each dView In activeSheet.DrawingViews
        dView.Label.FormattedText = dView.Label.FormattedText & "<Br/><DerivedProperty DerivedID='" & kDerivedDrawingFilename & "'></DerivedProperty>"
        Debug.Print dView.Label.FormattedText
    Next
End Sub

The text "FILENAME" as a content of DerivedProperty tag seems unnecessary.

If omitted, default text in your language is filled automatically.

("FILENAME" is set in English, and "ファイル名" is set in Japanese. "DATEINAME" will be set by your Inventor.)

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 5 of 6

dg2405
Advocate
Advocate

Thank's this was very helpful. But when i want the iProperty "Part Number"? This Property is not available in the DerivedPropertyTypeEnum.

0 Likes
Message 6 of 6

HideoYamada
Advisor
Advisor
Accepted solution

Hello,

 


@dg2405 wrote:

Thank's this was very helpful. But when i want the iProperty "Part Number"? This Property is not available in the DerivedPropertyTypeEnum.


You can know what string should be added by inserting a property and checking FormattedText.

 

For example, I inserted [Properties - Drawing]->[PART NUMBER] manually and following string was added to the FormattedText.

<Property Document='drawing' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property>

Copy this string into your code that sets FormattedText.

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes