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: 

Automatic dimensions and constraints - iLogic

4 REPLIES 4
Reply
Message 1 of 5
Ladousek
957 Views, 4 Replies

Automatic dimensions and constraints - iLogic

Hello, 

do you know how to use function "Automatic dimensions and constraints" in the sketch by iLogic? I would like to add dimensions to the sketch witch is drawn by defferent iLogic Rule step by step, line by line. Create sketch is not problem, but i would like to add dimensions to the lines. 

4 REPLIES 4
Message 2 of 5
RodrigoEiras
in reply to: Ladousek

Message 3 of 5
TobFischer94
in reply to: RodrigoEiras

i looked at the link by RodrigoEiras,

 

and theres a command called:

"SketchAutoDimensionCmd --> dimensions sketch geometry automatically"

 

you can run it by running an ilogic rule with the following code. Note that you must have created a Sketch called "Sketch1" containing geometry first:

 

    

 'Get the CommandManager object.
 Dim oCommandMgr As CommandManager
    oCommandMgr = ThisApplication.CommandManager

 ' Dim and select Sketch1
        Dim oSketches As PlanarSketches = ThisApplication.ActiveEditDocument.ComponentDefinition.Sketches
If TypeOf ThisApplication.ActiveEditObject Is Sketch Then
    Dim oSketch As Sketch = ThisApplication.ActiveEditObject
    oSketch.ExitEdit
End If
oSketches("Sketch1").Edit ' Get control definition for the line command. Dim oControlDef As ControlDefinition oControlDef = oCommandMgr.ControlDefinitions.Item( _ "SketchAutoDimensionCmd")
' Execute the command. Call oControlDef.Execute 

 

Message 4 of 5
TobFischer94
in reply to: TobFischer94

to simulate the pressing of the "apply" button that pops up, add the following code at the end of the ilogic-rule:

 

'Press Apply button
Dim oKCmd As ControlDefinition
Set oKCmd = ThisApplication.CommandManager.ControlDefinitions.Item("AppContextual_OKCmd")
Call oKCmd.Execute

Message 5 of 5

Thanks for the code. I like it. I modified a little bit - but, I need help.

I appreciate id you could fix the code for me.

 

2020-07-22 23_43_36-Window.png

 

'Get the CommandManager object.
 Dim oCommandMgr As CommandManager
    oCommandMgr = ThisApplication.CommandManager

 ' Dim and select Sketch1
        Dim oSketches As PlanarSketches = ThisApplication.ActiveEditDocument.ComponentDefinition.Sketches
If TypeOf ThisApplication.ActiveEditObject Is Sketch Then
    Dim oSketch As Sketch = ThisApplication.ActiveEditObject
    oSketch.ExitEdit
End If
    oSketches("Sketch1").Edit

    ' Get control definition for the line command. 
    Dim oControlDef As ControlDefinition 
    ' Get control definition for the line command. 
    oControlDef = oCommandMgr.ControlDefinitions.Item("SketchAutoDimensionCmd")  
	
oCount_Dimensions = 1 '1 is wrong. Need to fix code
oCount_Constraints = 1	'1 is wrong. Need to fix code

oYN = MessageBox.Show("Missing dimensions: " & oCount_Dimensions _
& vbLf & "Missing constraints: " & oCount_Constraints, _
"Do you want to add dimensions automatically?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)


If oYN = vbYes Then
Call oControlDef.Execute 
'Press Apply button
Dim oKCmd As ControlDefinition
oKCmd = ThisApplication.CommandManager.ControlDefinitions.Item("AppContextual_OKCmd")
Call oKCmd.Execute
Else
MessageBox.Show("Message", "Title")

'Code to add dimensions
End If

oSketches("Sketch1").ExitEdit

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

Post to forums  

Autodesk Design & Make Report