Hi, there are a couple of discussion for deleting all sketch constraints;
Is there a way to delete all sketch constraints apart from coincident constraints?
Thanks
Harry
Solved! Go to Solution.
Solved by rossano_praderi. Go to Solution.
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
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?
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.
Bregs
Rossano Praderi
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
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
Hi,
Thanks for that, quick question, why did you decide to do this within a transaction in this version?
Thanks Harry
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.