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: 

Macro for deleting certain types of sketch constraints

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
harrykeen18
824 Views, 8 Replies

Macro for deleting certain types of sketch constraints

Hi, there are a couple of discussion for deleting all sketch constraints;

 

http://forums.autodesk.com/t5/inventor-general-discussion/delete-all-constraints-in-a-sketch/td-p/25...

http://forums.autodesk.com/t5/inventor-general-discussion/remove-all-fixed-constraints-with-ilogic/t...

 

Is there a way to delete all sketch constraints apart from coincident constraints?

 

Thanks

 

Harry

8 REPLIES 8
Message 2 of 9

Hi Harry,
I'm not sure if this code is exactly what you need, but i would try.


This code to properly work have to be executed when you are editing a sketch.

 

' This is an Ilogic rule
Dim oActiveEditObject As Object oActiveEditObject = ThisApplication.ActiveEditObject ' If you want to convert it as VBA macro just put Set statement on the top of this line Dim entity As SketchEntity Dim oCont As GeometricConstraint On Error Resume Next If oActiveEditObject.Type = ObjectTypeEnum.kPlanarSketchObject Then For Each entity In oActiveEditObject.SketchEntities For Each oCont In entity.Constraints If oCont.Type <> kCoincidentConstraintObject Then oCont.Delete End If Next Next End If

 Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 3 of 9

Hi Rossano

 

Thanks for your reply. The macro seems to delete all constraints. I understand the <> means "does not equal" but it seems to delete them none the less...?

 

Effectively once I delete the constraints, the extrusion from the sketch fails because the sketch is no longer closed loop,  but its relatively easy to fix by running the diagnostics and clicking through until it has joined all the geometry with coincident constraints again. Would be good not to have to do this step though, do you have any suggestions?

Message 4 of 9

Hi Harry,

my code have few lines and is supposed to be an example on how to delete all constraints except the Coincident constraints, as your request.


If you want a bit more complex solution then let me know.


May be you have tried this solution, is it right for your needs.

 

http://forums.autodesk.com/t5/inventor-general-discussion/sketch-repair-amp-enhancement-tool-written...

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 5 of 9

Hi Rossano,

 

Sorry perhaps I wasn't clear in my last message, the code seems to delete all the constraints including conincident constraints despite the code looking like it should skip over them...

 

Am I implementing it incorrectly?

 

Thanks,

 

Harry

Message 6 of 9

Hi Harry,

Sorry for the mistake, I've forgot the "ObjectTypeEnum"...this is the corrected and tested code.

 

oTransMgr = ThisApplication.TransactionManager
oTrans = oTransMgr.StartTransaction(ThisApplication.ActiveDocument, "CancellaVincoli")
oActiveEditObject = ThisApplication.ActiveEditObject
Dim entity As SketchEntity

On Error Resume Next

If oActiveEditObject.Type = ObjectTypeEnum.kPlanarSketchObject Then
  For Each entity In oActiveEditObject.SketchEntities
    For Each oCont In entity.Constraints
	  If Not oCont.Type = ObjectTypeEnum.kCoincidentConstraintObject Then
		oCont.Delete
      End If
    Next
  Next
End If
oTrans.End

 

Please let me know if you need something else.

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 7 of 9

Hi,

 

Thanks for that, quick question, why did you decide to do this within a transaction in this version?

 

Thanks Harry

Message 8 of 9

Hi,

 

Thanks for that, quick question, why did you decide to do this within a transaction in this version?

 

Thanks Harry

Tags (1)
Message 9 of 9

Hi Harry,

With a transition you have only one operation to be undone, without transaction and with a loop in your code you have to undo each operation executed within your loop.

 

You know what I mean.



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------

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

Post to forums