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.
You can try this:
http://modthemachine.typepad.com/my_weblog/2009/03/running-commands-using-the-api.html
Good luck
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
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
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.
'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