Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create Text box in drawing using iLogic

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
Anonymous
6400 Views, 10 Replies

Create Text box in drawing using iLogic

Hi guys,

 

As shown above I was wondering if there is a way to create a text box to put in a certain place in the sheet using iLogic.

I have been looking around and haven't found any direct way of doing it that I could get to work so I'm looking for a little help.

 

Thanks,

 

Tom

10 REPLIES 10
Message 2 of 11
cwhetten
in reply to: Anonymous

Hi Tom, welcome to the forum.

 

Spoilered below is some sample code that adds text to a drawing sheet (it's called a "general note" in the API documentation).

 

Spoiler
Public Sub SheetTextAdd()
    ' 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 active sheet.
    Dim oActiveSheet As Sheet
    Set oActiveSheet = oDrawDoc.ActiveSheet
    
    ' Set a reference to the GeneralNotes object
    Dim oGeneralNotes As GeneralNotes
    Set oGeneralNotes = oActiveSheet.DrawingNotes.GeneralNotes
    
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry

    ' Create text with simple string as input. Since this doesn't use
    ' any text overrides, it will default to the active text style.
    Dim sText As String
    sText = "Drawing Notes"
    
    Dim oGeneralNote As GeneralNote
    Set oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(3, 18), sText)

    ' Create text using various overrides.
    sText = "Notice: All holes larger than 0.500 n are to be lubricated."
    Set oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(3, 16), sText)

    ' Create a set of notes that are numbered and aligned along the left.
    Dim dYCoord As Double
    dYCoord = 14
    Dim dYOffset As Double
    Dim oStyle As TextStyle
    Set oStyle = oGeneralNotes.Item(1).TextStyle
    dYOffset = oStyle.FontSize * 1.5

    ' Simple single line text.
    Set oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(3, dYCoord), "1.")
    sText = "This is note 1."
    Set oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(4, dYCoord), sText)

    ' Two line text. The two lines are defined using the  tag within the text string.
    dYCoord = dYCoord - (oGeneralNote.FittedTextHeight + 0.5)
    Set oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(3, dYCoord), "2.")
    sText = "This is note 2,  which contains two lines."
    Set oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(4, dYCoord), sText)

    ' Single line of text.
    dYCoord = dYCoord - (oGeneralNote.FittedTextHeight + 0.5)
    Set oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(3, dYCoord), "3.")
    sText = "This is note 3."
    Set oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(4, dYCoord), sText)

    ' Three lines of text.
    dYCoord = dYCoord - (oGeneralNote.FittedTextHeight + 0.5)
    Set oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(3, dYCoord), "4.")
    sText = "This is note 4,  which contains  several lines."
    Set oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(4, dYCoord), sText)

    dYCoord = dYCoord - (oGeneralNote.FittedTextHeight + 0.5)
    Set oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(3, dYCoord), "5.")
    
    sText = "Here is the last and final line of text."
    Set oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(4, dYCoord), sText)
End Sub

 

 

I copied this directly from the API help document.  You can find it in Inventor by going to the help dropdown (little arrow next the he "?" help button), then choosing Community Resources, then Programming Help:

 

API Help.png

 

In the API help document list of contents, expand the entry called "Inventor API Reference Manual" > "Objects".  Select the "DrawingNotes Object" entry.  You should see a list of properties, and under that, a list of samples.  Click the sample called "Add a general note".  You will see the code that I posted above.

 

That API help document is invaluable in programming with iLogic.

 

Post back if you have any questions about that sample code.  Good luck!

 

Please click "Accept as Solution" if this response answers your question.

Cameron Whetten
Inventor 2014

Message 3 of 11
Anonymous
in reply to: cwhetten

Thanks very much this is exactly what I was looking for.

 

Also thankyou for showing me the API help document! They will be very usefull.

 

Cheers,

 

Tom

Message 4 of 11
Anonymous
in reply to: cwhetten

Hi Cameron,

 

This code works great but I have another question now. I am trying to set the textbox font size upon creating it.

I am able to change it using

 

oStyle.fontsize=0.35

 

but this changes all text with that style to that size.

I haven't been able to figure out how to use a different style or to simply set for that unique box.

Would you be able to shed some light on this?

 

Thanks again,

 

Tom

Message 5 of 11
cwhetten
in reply to: Anonymous

It looks like text format overrides are controlled by some formatting code similar to html.  The only way I could get it to work was to specify the formatting code as part of the text string.  So, it would be something like this:

 

Spoiler
oSheet = ThisDoc.Document.Sheets(1)

oGenNotes = oSheet.DrawingNotes.GeneralNotes

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

sText = "MY TEXT HERE"
sFormattedText = "<StyleOverride FontSize = '0.35'>" & sText & "</StyleOverride>"

oGenNotes.AddFitted(oTG.CreatePoint2d(3, 18), sFormattedText)

It's a little awkward, but it will get the job done.  If you want to add line breaks into your text note, put <Br/> in your text string anywhere you want one.  For example:

sText = "THIS IS THE FIRST LINE<Br/>AND THIS IS THE SECOND LINE"

 

You can also specify a text style when you create the note.  This is slightly more complicated, but post back if you would like me to explain it.

 

Cameron Whetten
Inventor 2014

 

Message 6 of 11
Anonymous
in reply to: cwhetten

Fantastic thanks again Cameron.

 

I only needed to change the font size so no need to explain about the text style but thankyou for the offer.

 

Cheers,

 

Tom

Message 7 of 11
Anonymous
in reply to: Anonymous

treavie, I'm using Inventor Pro 2015, and I do not see Community Resources under the Help menu. Where can I find it?
Message 8 of 11
Anonymous
in reply to: Anonymous

Sorry, meant cwhetton lol
Message 9 of 11
cwhetten
in reply to: Anonymous


@Anonymous wrote:
treavie, I'm using Inventor Pro 2015, and I do not see Community Resources under the Help menu. Where can I find it?

They moved it after version 2014.  In version 2016 (and hopefully version 2015), it can be found here:

 

API Help post-2014.png

 

Cameron Whetten
Inventor 2016

Message 10 of 11
roberto_infanti
in reply to: cwhetten

Hello, can you give me confirmation that it still works with the 2022 version? If it works, what initial settings do you need to make? I have INVENTOR in Italian.

Message 11 of 11
johnsonshiue
in reply to: Anonymous

Hi Roberto,

 

You may copy and paste the sample code from the following page to an iLogic rule. This is an example of creating a stacked text.

 

https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-B992AA27-7492-4B16-87E1-E5E4A30B9249

 

Some of the code may need to be adjusted to VB.Net. Just follow the prompted message to correct it accordingly.

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer

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

Post to forums  

Autodesk Design & Make Report