Hallo Communitie,
i have a question about an idea that I have in the Inventor drawing.
Is it possible to take a specific sketch symbol to all dimensions in a drawing. The sketch symbol is a simple ballon with a number, but the number shoud count the dimensions inside the drawing.
This is a question from a coustomer. And because I have not so much programming in my life I try to ask the profies here
Solved! Go to Solution.
Solved by Jef_E. Go to Solution.
I believe anything is possible and so is this one.
I took it upon me to even check how you can do this, and based on this sample it should be possible.
Public Sub CreateSketchedSymbolDefinition() ' Set a reference to the drawing document. ' This assumes a drawing document is active. Dim oDrawDoc As DrawingDocument Set oDrawDoc = ThisApplication.ActiveDocument ' Create the new sketched symbol definition. Dim oSketchedSymbolDef As SketchedSymbolDefinition Set oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Add("Circular Callout") ' Open the sketched symbol definition's sketch for edit. This is done by calling the Edit ' method of the SketchedSymbolDefinition to obtain a DrawingSketch. This actually creates ' a copy of the sketched symbol definition's and opens it for edit. Dim oSketch As DrawingSketch Call oSketchedSymbolDef.Edit(oSketch) Dim oTG As TransientGeometry Set oTG = ThisApplication.TransientGeometry ' Use the functionality of the sketch to add sketched symbol graphics. Dim oSketchLine As SketchLine Set oSketchLine = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0, 0), oTG.CreatePoint2d(20, 0)) Dim oSketchCircle As SketchCircle Set oSketchCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(22, 0), 2) Call oSketch.GeometricConstraints.AddCoincident(oSketchLine.EndSketchPoint, oSketchCircle) ' Make the starting point of the sketch line the insertion point oSketchLine.StartSketchPoint.InsertionPoint = True ' Add a prompted text field at the center of the sketch circle. Dim sText As String sText = "<Prompt>Enter text 1</Prompt>" Dim oTextBox As TextBox Set oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(22, 0), sText) oTextBox.VerticalJustification = kAlignTextMiddle oTextBox.HorizontalJustification = kAlignTextCenter Call oSketchedSymbolDef.ExitEdit(True) End Sub Public Sub InsertSketchedSymbolOnSheet() ' Set a reference to the drawing document. ' This assumes a drawing document is active. Dim oDrawDoc As DrawingDocument Set oDrawDoc = ThisApplication.ActiveDocument ' Obtain a reference to the desired sketched symbol definition. Dim oSketchedSymbolDef As SketchedSymbolDefinition Set oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item("Circular Callout") Dim oSheet As Sheet Set oSheet = oDrawDoc.ActiveSheet ' This sketched symbol definition contains one prompted string input. An array ' must be input that contains the strings for the prompted strings. Dim sPromptStrings(0) As String sPromptStrings(0) = "A" Dim oTG As TransientGeometry Set oTG = ThisApplication.TransientGeometry ' Add an instance of the sketched symbol definition to the sheet. ' Rotate the instance by 45 degrees and scale by .75 when adding. ' The symbol will be inserted at (0,0) on the sheet. Since the ' start point of the line was marked as the insertion point, the ' start point should end up at (0,0). Dim oSketchedSymbol As SketchedSymbol Set oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oTG.CreatePoint2d(0, 0), (3.14159 / 4), 0.75, sPromptStrings) End Sub
Now this sample is not bullet proof as all values in the balloon will be value "A"
' This sketched symbol definition contains one prompted string input. An array ' must be input that contains the strings for the prompted strings. Dim sPromptStrings(0) As String sPromptStrings(0) = "A"
So we still need to count ALL dimensions on the drawing. ( note that this will also include dimensions outside the drawing frame )
To count the dimensions it's quite simple as I looked into the API for a sheet object.
Name | Description |
Arrange | Method that automatically arranges the input drawing dimensions. |
Name | Description |
Application | Returns the top-level parent application object. When used the context of Inventor, an Application object is returned. When used in the context of Apprentice, an ApprenticeServer object is returned. |
BaselineDimensionSets | Property that returns the BaselineDimensionSets collection object. |
ChainDimensionSets | Property that returns the ChainDimensionSets collection object. This object provides access to all of the chain dimension sets on the sheet and provides functionality to create new chain dimension sets. |
Count | Property that returns the number of items in the collection. |
GeneralDimensions | Property that returns the GeneralDimensions collection object. This object provides access to all of the general dimensions on the sheet and provides functionality to create new general dimensions. |
Item | Method that returns the specified dimension object from the collection. |
OrdinateDimensions | Property that returns the OrdinateDimensions collection object. |
OrdinateDimensionSets | Property that returns the OrdinateDimensionSets collection object. |
Type | Returns an ObjectTypeEnum indicating this object's type. |
Name | Description |
Baseline dimension sets | This sample demonstrates the creation of a baseline set dimension in a drawing. |
Dimensions - edit | This sample demonstrates the editing of sheet dimensions and the associated dimension style. |
As you can see there is a count function, this will count the number of dimensions of the type
So there only rests one task and put this information to the task, I hope you will try and do this yourself. It shouldn't be that hard, just open the iLogic browser and give it a whirl!
If you have no success or simply don't want to try, look at the spoiler below for a working code.
Code that creates a symbol and fills the value
Sub Main CreateSketchedSymbolDefinition() ' a reference to the drawing document. ' This assumes a drawing document is active. Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument ' Create the new sketched symbol definition. Dim oSketchedSymbolDef As SketchedSymbolDefinition oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Add("Circular Callout") ' Open the sketched symbol definition's sketch for edit. This is done by calling the Edit ' method of the SketchedSymbolDefinition to obtain a DrawingSketch. This actually creates ' a copy of the sketched symbol definition's and opens it for edit. Dim oSketch As DrawingSketch Call oSketchedSymbolDef.Edit(oSketch) Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry ' Use the functionality of the sketch to add sketched symbol graphics. Dim oSketchLine As SketchLine oSketchLine = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0, 0), oTG.CreatePoint2d(20, 0)) Dim oSketchCircle As SketchCircle oSketchCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(22, 0), 2) Call oSketch.GeometricConstraints.AddCoincident(oSketchLine.EndSketchPoint, oSketchCircle) ' Make the starting point of the sketch line the insertion point oSketchLine.StartSketchPoint.InsertionPoint = True ' Add a prompted text field at the center of the sketch circle. Dim sText As String sText = "<Prompt>Enter text 1</Prompt>" MsgBox("1") Dim oTextBox As TextBox oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(22, 0), sText) MsgBox("2") oTextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle MsgBox("3") oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter Call oSketchedSymbolDef.ExitEdit(True) Call InsertSketchedSymbolOnSheet() End Sub Public Sub InsertSketchedSymbolOnSheet() ' a reference to the drawing document. ' This assumes a drawing document is active. Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument ' Obtain a reference to the desired sketched symbol definition. Dim oSketchedSymbolDef As SketchedSymbolDefinition oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item("Circular Callout") Dim oSheet As Sheet oSheet = oDrawDoc.ActiveSheet ' This sketched symbol definition contains one prompted string input. An array ' must be input that contains the strings for the prompted strings. Dim sPromptStrings(0) As String sPromptStrings(0) = oSheet.DrawingDimensions.Count Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry ' Add an instance of the sketched symbol definition to the sheet. ' Rotate the instance by 45 degrees and scale by .75 when adding. ' The symbol will be inserted at (0,0) on the sheet. Since the ' start point of the line was marked as the insertion point, the ' start point should end up at (0,0). Dim oSketchedSymbol As SketchedSymbol oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oTG.CreatePoint2d(0, 0), (3.14159 / 4), 0.75, sPromptStrings) End Sub
Code that inserts a specific symbol and adds the value. Change the symbol name where marked with red.
' a reference to the drawing document. ' This assumes a drawing document is active. Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument ' Obtain a reference to the desired sketched symbol definition. ' Change the name here!!! Dim oSketchedSymbolDef As SketchedSymbolDefinition oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item("Circular Callout") Dim oSheet As Sheet oSheet = oDrawDoc.ActiveSheet ' This sketched symbol definition contains one prompted string input. An array ' must be input that contains the strings for the prompted strings. Dim sPromptStrings(0) As String sPromptStrings(0) = oSheet.DrawingDimensions.Count Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry ' Add an instance of the sketched symbol definition to the sheet. ' Rotate the instance by 45 degrees and scale by .75 when adding. ' The symbol will be inserted at (0,0) on the sheet. Since the ' start point of the line was marked as the insertion point, the ' start point should end up at (0,0). Dim oSketchedSymbol As SketchedSymbol oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oTG.CreatePoint2d(0, 0), (3.14159 / 4), 0.75, sPromptStrings)
If you don't like the positioning please change the text marked with blue according the method below
Name | Description |
SketchedSymbolDefinition | Input Variant that specifies which SketchedSymbolDefinition to use. The input for the argument can be either a SketchedSymbolDefinition object or string containing the name of an existing SketchedSymbolDefinition object. |
Position | Input that specifies the location on the sheet to place the sketched symbol instance. |
Rotation | The rotation of the symbol, in radians. |
Scale | The scale of the symbol. |
PromptStrings | Optional input array of Strings that specifies the input strings to use as input for prompted text fields that my be present in the sketched symbol definition. If prompted strings exist in the sketched symbol definition you must supply input strings through this argument or this method will fail. The prompt strings and their order are obtained by querying the TextBox objects in the SketchedSymbolDefinition. The order they're returned by the TextBoxes collection is the same order the input strings need to be supplied in the PromptStrings array. |
Name | Description |
Create SketchedSymbol Definition | This sample illustrates creating a new sketched symbol definition object and inserting it into the active sheet. |
Sorry for the long post, I hope you find this insightful.
Hi Jef,
boahhh, thank, many thank for your help.
I try it out what you give me.
I hope that I understand all because as I say, I'm not a programmer.
but, again, thank you
No problem, if you like the help please kudo the author and if it works accept as solution 😉
When you run into problem(s) please let me know.
HI Jef,
your cods work perfect and it is a good start in the right way.
I attach a picture where you can see what my customer want.
As you can see he want at any dimensions a seperate callout with a number. He use the numbers as a number for his check prozess.
Wow, did I misunderstand that.. I thought you wanted a symbol with them number of the tot dimension count. I guess this is also possible but I don't have the time to check this untill monday. I will check it then. Have a good weekend ( we have a holiday tomorrow and need to do loads of construction work! )
No Problem Jef,
I'm glad that you help me.
Have a nice holiday and a nice weekend.
by
Jörg
After giving it a sleepy monday morning think, I might found the solution..
Only thing I need to know is, do you want to select the dimensions one by one, or balloon them all at once? Maybe one by one is more efficient for future revisions?
Please note that this solution will reuses deleted dimension numbers; example: dimension 4 is deleted , and a new dimension is added. This will be dimension 4.
I think one by one is the better way. It will be the first time more work, but if you add some new deminsions, the existing demensions will hod the existing ballon.
Okay,
I modified my code a bit, and got this is the result. It places the balloon on the dimension text. Don't forget to edit the sketchsymbol name marked in red.
' a reference to the drawing document. ' This assumes a drawing document is active. Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument ' Obtain a reference to the desired sketched symbol definition. ' Change the name here!!! Dim oSketchedSymbolDef As SketchedSymbolDefinition oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item("Dimension tag") ' Set refence to the active sheet. Dim oSheet As Sheet oSheet = oDrawDoc.ActiveSheet ' Check selected dimension If oDrawDoc.SelectSet.Count = 1 Then If TryCast(oDrawDoc.SelectSet.Item(1), DrawingDimension) Is Nothing Then MsgBox("Please select a dimension") Exit Sub End If Else MsgBox("None or too many dimension(s) selected") Exit Sub End If ' Get the index of the selected drawingdimension Dim oDim As DrawingDimension oDim = oDrawDoc.SelectSet.Item(1) ' Set a counter Dim i As Integer i = 1 Dim sPromptStrings(0) As String ' Loop all dimension to find the index For Each dimension As DrawingDimension In oSheet.DrawingDimensions ' Look for a match If dimension Is oDim Then ' This sketched symbol definition contains one prompted string input. An array ' must be input that contains the strings for the prompted strings. sPromptStrings(0) = i ' The match is found exit the loop ' No more counting required Exit For End If ' Add to the count i += 1 Next ' Add an instance of the sketched symbol definition to the sheet. Dim oSketchedSymbol As SketchedSymbol oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oDim.Text.Origin, , , sPromptStrings)
You should add the rule as iLogic button, then select a dimension and press the button.
Thanks a lot to this point.
You are fantastic.
I will test it tomorrow but I'm sure it work fine.
Again, thanks a lot.
And by the way, I will tell everyone that the solution is not form me, it is from you.
Hi Jef,
i test it and it work fine.
Thanks for your help.
Have a nice day.
Can't find what you're looking for? Ask the community or share your knowledge.