How does Inventor "Remove fix constraints" so quickly? Can this be replicated in iLogic?
The way I've previously done this requires looping through the constraint collection and deleting one at a time which may take a few minutes on a complex sketch, but when Inventor deletes fixed constraints throught the menu option it does it in a few seconds on the same sketch so Inventor must be able to select them all at once and delete them all at once. Is there a way to do this through the API or iLogic?
Thanks,
Steve
Sorry it took so long to get back to this. Thanks for showing me that command, by the way. I had never seen that before.
Below is an iLogic rule that might work. I haven't actually tried it on a huge complex sketch. I don't have any of those--it is best practice to keep your sketches as simple as possible. But, it seems to work well on the sketches I tried. Give it a try and see if it will do what you need.
Dim oSelectSet As SelectSet oSelectSet = ThisDoc.Document.SelectSet oSelectSet.Clear() Dim oActiveEditObject As Object oActiveEditObject = ThisApplication.ActiveEditObject If oActiveEditObject.Type = ObjectTypeEnum.kPlanarSketchObject Then For Each entity As SketchEntity In oActiveEditObject.SketchEntities oSelectSet.Select(entity) Next ThisApplication.CommandManager.ControlDefinitions.Item("SketchUnfixCmd").Execute() oSelectSet.Clear() Else MessageBox.Show("Activate a 2D sketch before running this rule.", "iLogic Rule: Remove Fix Constraints") End If
I have also attached the rule in TXT format because sometimes copying and pasting iLogic code from the discussion board creates code problems.
Cameron Whetten
Inventor 2014
Please click "Accept as Solution" if this response answers your question.
@ad64 wrote:
In 2013, you select sketch geometry and right-click. It appears under the pop-up menu.
Steve
That is interesting. I guess because I (almost) never use Fixed Constraint (and certainly would not likely have more than one) I never knew that was there.
I don't use the fixed command either in regular modelling, but this was for my Sketch Repair Tool: http://forums.autodesk.com/t5/Autodesk-Inventor/Sketch-Repair-amp-Enhancement-Tool-written-in-iLogic...
When the Sketch Repair Tool auto-constrains tangent lines and curves or synchronizes the radii in a sketch it needs to ground all of the straight lines so that the actual shape and size of the profile is not altered. This command is commonly used to auto-constrain geometry brought in from AutoCAD but is also useful when repairing poorly constrained Inventor sketches.
Currently the code in the Sketch Repair Tool loops through all of the geometry searching for fixed constraints to remove them at the end of the routine, but I am looking for a way to expedite it by removing them all at once like Inventor does.
I'm going to test out Cameron's code above and see if it improves performance. Thanks for the idea, Cameron.
Steve
Can you check the url? I think it is broken. I would like to check out your Sketch Repair Tool.
Never mind - I found it.
I've edited the above post to repair the link. It should be working now.
If the link is still broken, you might try searching the forum for the thread: "Sketch Repair & Enhancement Tool written in iLogic."
Steve
Cameron's code is significantly faster, but I notice that it still selects entities one at a time. Is there anyway to "select all"?
What I've tried:
- selecting the entities all at once - oSelectSet.SelectMultiple(oSketch.SketchEntities) / oSelectSet.SelectMultiple(oSketch.SketchLines). It errored out.
- selecting the sketch as a whole - oSelectSet.Select(oSketcht) - which it successfully did but the command to unground did not do anything.
Are there any other suggestions.
Steve
The Mod the Machine blog is an excellent resource for learning how to program in Inventor. The following links to an article that describes how to get a list of commands to call from the CommandManager:
http://modthemachine.typepad.com/my_weblog/2009/03/running-commands-using-the-api.html
I used their little program to get the list that is attached. This list is from Inventor 2014, so it may be slightly different than what you have in 2011. You may want to run the little program to get a list for your version.
Cameron Whetten
Inventor 2014
Using EventWatcher I obtained the command name:
ThisApplication.CommandManager.ControlDefinitions.Item("SketchUnfixCmd").execute
However, I still have the same problem as before: I am unable to automatically select all the geometry at once.
If I select the entire sketch as a whole Inventor sees this as only one entity and does not remove the constraints from the individual items. I have not been able to add the SketchEntities en masse to the select set.
Dim oSketch As Sketch = ThisApplication.ActiveEditObject 'Current Sketch Dim oSelectSet As SelectSet = ThisDoc.Document.SelectSet oSelectSet.Select(oSketch) ThisApplication.CommandManager.ControlDefinitions.Item("SketchUnfixCmd").execute
Any ideas on how to select all the sketch entities at once (or even all of the sketch lines at once) without user intervention?
Thanks,
Steve
check out the below code & link....hope it will be useful.....
Sub deleteconstraints()
Dim oPartDoc As PartDocument
Dim oSketch As PlanarSketch
Dim geoconstraint As GeometricConstraint
On Error Resume Next
Set oPartDoc = ThisApplication.ActiveDocument
For Each oSketch In oPartDoc.ComponentDefinition.Sketches
For Each geoconstraint In oSketch.GeometricConstraints
Call geoconstraint.Delete
Next geoconstraint
Next oSketch
MsgBox( "All constraints deleted!")
End Sub
Carthik,
The method you suggest is what I originally had, but it is much slower than triggering Inventor's built-in "Remove all Fixed Constraints" command.
The only obstacle to using the faster command is finding a way to select all of the sketch geometry so that I can run it. The user can easily do this with his mouse, but it is not as easy to get Inventor to automatically do it.
Steve