- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is there any way to programmatically remove a projected loop that was become sick? From the UI you can right click on the loop and select delete. Unfortunately, I can't find a way to remove this from the API. Essentially want to be able to search all sketches and identify/delete any broken references.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
I'm not sure, but sick sketch entites seems to be a combination of Reference property is set to true but ReferencedEntity property is nothing. This iLogic should do.
Dim oPartDoc As PartDocument = ThisDoc.Document
Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oPartDoc, "CleanSickSketchEntities")
Try
ThisApplication.ScreenUpdating=False
Dim oSketch As PlanarSketch
Dim oSketchEnt As SketchEntity
For Each oSketch In oPartDoc.ComponentDefinition.Sketches
oSketch.Edit
For Each oSketchEnt In oSketch.SketchEntities
If oSketchEnt.Reference = True Then
If oSketchEnt.ReferencedEntity Is Nothing Then
If Not oSketchEnt.Type = kSketchPointObject Then
'delete sick entity
oSketchEnt.Delete
'unlink sick entity to normal sketch ent
'oSketchEnt.Reference=False
End If
End If
End If
Next
oSketch.ExitEdit
Next
Catch
Finally
ThisApplication.ScreenUpdating = True
oTrans.End
End Try
R. Krieg
RKW Solutions
www.rkw-solutions.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks for trying, but unfortunately that doesn't work. We have similar code in our C# code that worked great in 2019, but stopped working in 2020/2021. Code will let you set the reference to false, but fails when you try to delete it. Appears to be some NOT publicly visible link to the browser node when a face is projected. Unfortunately, when the projected face is no longer available the associated edge loop just kind of disappears for visibility to the API. Interestingly, when I started testing by selecting the browser node and checking what was available under the selection states the selected item is Nothing. I'll submit an error report to ADSK once I get some time to produce a stripped down sample. Was hoping maybe someone else had already ran into this.
Thanks,
William Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I tried this before too. After checking that the 'Reference' boolean is True, and that the 'ReferencedEntity' was nothing, I then entered into Edit mode for the sketch, then used a Try...Catch block of code around my 'Delete' method, to avoid the expected errors. When I put a MsgBox in the Catch portion, it would show that MsgBox some times, but the 'sick' projected geometry was gone when the rule finished, so it did do it's job for me. I didn't bother trying to set the 'Reference' property to False, because the geometry object is already in an error state.
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
For Each oSketch As PlanarSketch In oPDef.Sketches
For Each oSE As SketchEntity In oSketch.SketchEntities
If oSE.Reference Then
If oSE.ReferencedEntity Is Nothing Then
oSketch.Edit
Try
oSE.Delete
Catch
'MsgBox("Couldn't delete it.", , "")
End Try
oSketch.ExitEdit
End If
End If
Next
Next
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS)
.
If you want and have time, I would appreciate your Vote(s) for My IDEAS
or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I found a way using CommandManager to replicate the UI command "DeleteConstraints". Sketch Enties that are part of a sick Projected Loop can't be deleted until their constraints are deleted. You need to do this all at once though because if you delete constraints from part of the loop, the rest of the sketch entities in that loop are no longer sick and won't get picked up/Deleted by the rule.
Try this out:
Dim oPartDoc As PartDocument = ThisDoc.Document
Dim deleteConstraintsCMD As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("SketchDeleteConstraintsCtxCmd")
Dim sickCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim selSet As SelectSet = oPartDoc.SelectSet
Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oPartDoc, "Delete Sick Sketch Entities")
On Error GoTo ERRR
For Each oSketch As PlanarSketch In oPartDoc.ComponentDefinition.Sketches
selSet.Clear
oSketch.Edit
For Each oSketchEnt As SketchEntity In oSketch.SketchEntities
If oSketchEnt.Reference = True Then
If oSketchEnt.ReferencedEntity Is Nothing Then
If Not oSketchEnt.Type = kSketchPointObject Then
'Collect all sick entities
sickCollection.Add(oSketchEnt)
End If
End If
End If
Next
'Select All Sick Entities
selSet.SelectMultiple(sickCollection)
'Delete All constraints on selected entities
deleteConstraintsCMD.Execute
'Loop through and delete all previously sick entities
For Each Item In sickCollection
Item.Delete
Next
oSketch.ExitEdit
Next
oTrans.End
Exit Sub
ERRR :
oTrans.Abort
Logger.Trace("Failure")
Let me know if you have any questions, or if this is not working as intended.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks for all the suggestions. After further testing, seeing a hard crash (both 2021 & 2022) even attempting to look at the ReferencedEntity property. It has been submitted to ADSK as a bug.
William Graham.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This is not good programming. Is there a way to check the feature is not valid before the delete throws and error.