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
Solved! Go to Solution.
Solved by cwhetten. Go to Solution.
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).
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:
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
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
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
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:
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
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
@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:
Cameron Whetten
Inventor 2016
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.
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!