Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Question about it is possible or not

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
j_weber
2978 Views, 12 Replies

Question about it is possible or not

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

 

 




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





12 REPLIES 12
Message 2 of 13
Jef_E
in reply to: j_weber

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.

 

Spoiler
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.

 

Spoiler
DrawingDimensions Object

DrawingDimensions Object

Description

The DrawingDimensions object provides access to all of the dimensions ( objects) on the sheet.

Methods

Name Description
Arrange Method that automatically arranges the input drawing dimensions.

Properties

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.

Samples

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.

Version

Introduced in Inventor version 9

 

 

 

As you can see there is a count function, this will count the number of dimensions of the type

  •  Baseline dimension
  • Chain dimension
  • General dimensions
  • Ordinate dimensions
  • Ordinate set dimensions

 

Spoiler
DrawingDimensions.Count Property

DrawingDimensions.Count Property

Parent Object: DrawingDimensions

Description

Property that returns the number of items in the collection.

Syntax

DrawingDimensions.Count() As Long

Version

Introduced in Inventor version 9

 

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

Spoiler
SyntaxEditor Code Snippet
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.

Spoiler
    ' 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

Spoiler
SketchedSymbols.Add Method

SketchedSymbols.Add Method

Parent Object: SketchedSymbols

Description

Method that places a sketched symbol onto the sheet.

Syntax

SketchedSymbols.Add( SketchedSymbolDefinition As Variant, Position As Point2d, [Rotation] As Double, [Scale] As Double, [PromptStrings] As Variant ) As SketchedSymbol

Parameters

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.

Samples

Name Description
Create SketchedSymbol Definition This sample illustrates creating a new sketched symbol definition object and inserting it into the active sheet.

Version

Introduced in Inventor version 5.3

 

Sorry for the long post, I hope you find this insightful.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 3 of 13
j_weber
in reply to: Jef_E

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




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





Message 4 of 13
Jef_E
in reply to: j_weber

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.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 5 of 13
j_weber
in reply to: Jef_E

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. 

 

ballon.jpg

 

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. 




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





Message 6 of 13
Jef_E
in reply to: j_weber

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! )



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 7 of 13
j_weber
in reply to: Jef_E

No Problem Jef,

I'm glad that you help me.

 

Have a nice holiday and a nice weekend.

 

by

Jörg




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





Message 8 of 13
Jef_E
in reply to: j_weber

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.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 9 of 13
j_weber
in reply to: Jef_E

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.




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





Message 10 of 13
Jef_E
in reply to: j_weber

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.

 

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 11 of 13
j_weber
in reply to: Jef_E

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.




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





Message 12 of 13
j_weber
in reply to: Jef_E

Hi Jef,

i test it and it work fine.

 

Thanks for your help.

 

Have a nice day.




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





Message 13 of 13
Anonymous
in reply to: j_weber

can I get the code and a video or pictures  explaining the process with example

 

Thanks in advance

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

Post to forums  

Autodesk Design & Make Report