remove projected (sketchpoint) geometie from an other part in active sketch

remove projected (sketchpoint) geometie from an other part in active sketch

robbeRtek
Advocate Advocate
735 Views
5 Replies
Message 1 of 6

remove projected (sketchpoint) geometie from an other part in active sketch

robbeRtek
Advocate
Advocate

Hello,

We have a composition with a layout part and various components. When we click on a component (using a macro), we want to remove projected geometry from the initial sketch of this component. (The projected geometry consists of projected sketch points from a layout part).

Manually, the action is as follows: edit sketch -> select references in the browser and 'break link,' and optionally clean up the sketch by effectively removing projected geometry.

With the code, I can effectively locate and remove the projected points from the sketch after setting the 'boolean reference' to false. After this action, you can adjust the quadrilateral, but in the browser, the three references remain with an error message. Right-clicking doesn't provide any options.

In the sketch itself, the new option 'select broken projections' is disabled.

Does anyone know how to resolve/address this issue of removing projected sketch references with code?

(same test results in inventor 2019 en 2023)

 

Thank you for your feedback.

Here is the code:

(vbnet)

Dim obj As Object = _invApp.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "select part")
If obj Is Nothing Or Not obj.type = ObjectTypeEnum.kSurfaceBodyProxyObject Then Exit Sub
Dim SfbodieProxy As SurfaceBodyProxy = obj
Dim occ As ComponentOccurrence = SfbodieProxy.ContainingOccurrence
Dim itemDef As PartComponentDefinition = occ.Definition
Dim sketchBase_ As PlanarSketch = itemDef.Sketches.Item(1)
' Collect projection sketch points in a HashSet
Dim PntjCollection As New HashSet(Of SketchPoint)
For Each p As SketchPoint In sketchBase_.SketchPoints
If Not (p.Geometry.X = 0 AndAlso p.Geometry.Y = 0) Then
If p.Reference Then 'or center hole
PntjCollection.Add(p)
End If
End If
Next
sketchBase_.Edit()
For Each p As SketchPoint In PntjCollection
p.Reference = False
p.Delete()
Next
sketchBase_.ExitEdit()

 

0 Likes
736 Views
5 Replies
Replies (5)
Message 2 of 6

robbeRtek
Advocate
Advocate

@johnsonshiue
Can you help with acces this problem?

I've tested yet with 'sketchBase_.breaklinks()' but it don't work either.

Many thanks.

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor

Hi @robbeRtek.  This certainly sounds like a complicated process to automate correctly.  I see that you mentioned testing the PlanarSketch.BreakLink method, and that not working for you.  There is also the UpdateProfiles method and Solve method you could test after edits have been made?  I also found that new command that they just added, which you are pointing to in one of your attached images ("SketchSelectBrokenProjectionsCmd").  I have not had a chance to test it by code yet, but I would assume that you would need to have the Sketch in Edit Mode first, and/or you may need to add the Sketch itself to the Document.SelectSet of the component document you are editing at the time, before executing that command.  Often times executing commands will invoke user interface tools to show, prompting manual user interactions though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

Frederick_Law
Mentor
Mentor

And they are all Adaptive .....

0 Likes
Message 5 of 6

robbeRtek
Advocate
Advocate

still no solution,

here is an snippet code from autodesk to make  projections  a cross parts :
(make an new assembly and add 2 different new parts.)

vba :

Public Sub ProjectingAcrossParts()
    ' Set a reference to the assembly component definition.
    Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

    ' Get references to two occurrences.
    ' This arbitrarily gets the first and second occurrence.
    Dim oOcc1 As ComponentOccurrence
    Set oOcc1 = oAsmCompDef.Occurrences.Item(1)

    Dim oOcc2 As ComponentOccurrence
    Set oOcc2 = oAsmCompDef.Occurrences.Item(2)

    ' Create a sketch on the first part.
    Dim oSketch1 As PlanarSketch
    Set oSketch1 = oOcc1.Definition.Sketches.Add(oOcc1.Definition.WorkPlanes(1))

    ' Set a reference to the transient geometry collection.
    Dim oTransGeom As TransientGeometry
    Set oTransGeom = ThisApplication.TransientGeometry

    ' Create a sketch line on the sketch.
    Dim oSketchLine1 As Object
    Set oSketchLine1 = oSketch1.SketchLines.AddByTwoPoints(oTransGeom.CreatePoint2d(0, 0), _
    oTransGeom.CreatePoint2d(4, 0))

    ' Because we need the sketch line in the context of the assembly
    ' we need to create a proxy for the sketch line. The proxy
    ' represents the sketch line in the context of the assembly.
    Dim oSketchLine1Proxy As Object
    Call oOcc1.CreateGeometryProxy(oSketchLine1, oSketchLine1Proxy)

    ' Create a sketch on the second part.
    Dim oSketch2 As PlanarSketch
    Set oSketch2 = oOcc2.Definition.Sketches.Add(oOcc2.Definition.WorkPlanes(1))

    ' Create a proxy for the sketch in the second part.
    Dim oSketch2Proxy As PlanarSketchProxy
    Call oOcc2.CreateGeometryProxy(oSketch2, oSketch2Proxy)

    ' Project the line in the sketch in the first
    ' part to the sketch in the second part
    Dim oSketchLine2Proxy As SketchLineProxy
    Set oSketchLine2Proxy = oSketch2Proxy.AddByProjectingEntity(oSketchLine1Proxy)
End Sub

ilogic :

Public Sub main()
    ' Set a reference to the assembly component definition.
    Dim oAsmCompDef As AssemblyComponentDefinition
    oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

    ' Get references to two occurrences.
    ' This arbitrarily gets the first and second occurrence.
    Dim oOcc1 As ComponentOccurrence
    oOcc1 = oAsmCompDef.Occurrences.Item(1)

    Dim oOcc2 As ComponentOccurrence
    oOcc2 = oAsmCompDef.Occurrences.Item(2)

    ' Create a sketch on the first part.
    Dim oSketch1 As PlanarSketch
    oSketch1 = oOcc1.Definition.Sketches.Add(oOcc1.Definition.WorkPlanes(1))

    ' Set a reference to the transient geometry collection.
    Dim oTransGeom As TransientGeometry
    oTransGeom = ThisApplication.TransientGeometry

    ' Create a sketch line on the sketch.
    Dim oSketchLine1 As Object
    oSketchLine1 = oSketch1.SketchLines.AddByTwoPoints(oTransGeom.CreatePoint2d(0, 0), _
    oTransGeom.CreatePoint2d(4, 0))

    ' Because we need the sketch line in the context of the assembly
    ' we need to create a proxy for the sketch line. The proxy
    ' represents the sketch line in the context of the assembly.
    Dim oSketchLine1Proxy As Object
    oOcc1.CreateGeometryProxy(oSketchLine1, oSketchLine1Proxy)

    ' Create a sketch on the second part.
    Dim oSketch2 As PlanarSketch
    oSketch2 = oOcc2.Definition.Sketches.Add(oOcc2.Definition.WorkPlanes(1))

    ' Create a proxy for the sketch in the second part.
    Dim oSketch2Proxy As PlanarSketchProxy
    oOcc2.CreateGeometryProxy(oSketch2, oSketch2Proxy)

    ' Project the line in the sketch in the first
    ' part to the sketch in the second part
    Dim oSketchLine2Proxy As SketchLineProxy
    oSketchLine2Proxy = oSketch2Proxy.AddByProjectingEntity(oSketchLine1Proxy)
End Sub

 and run this snippet.
Now there in the second part an sketch with an cross-part-reference.
How can i break this link, without having errors?? (with code)
(i want to do this : oSketch2Proxy.RemoveProjectingEntityLink(oSketch2Proxy ) (or delete the object  projectoSketch2Proxy)

i try it :

ilogic :

Public Sub main()
    ' Set a reference to the assembly component definition.
    Dim oAsmCompDef As AssemblyComponentDefinition
    oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

    ' Get references to two occurrences.
    ' This arbitrarily gets the first and second occurrence.
    Dim oOcc1 As ComponentOccurrence
    oOcc1 = oAsmCompDef.Occurrences.Item(1)

    Dim oOcc2 As ComponentOccurrence
    oOcc2 = oAsmCompDef.Occurrences.Item(2)

    ' Create a sketch on the first part.
    Dim oSketch1 As PlanarSketch
    oSketch1 = oOcc1.Definition.Sketches.Add(oOcc1.Definition.WorkPlanes(1))

    ' Set a reference to the transient geometry collection.
    Dim oTransGeom As TransientGeometry
    oTransGeom = ThisApplication.TransientGeometry

    ' Create a sketch line on the sketch.
    Dim oSketchLine1 As Object
    oSketchLine1 = oSketch1.SketchLines.AddByTwoPoints(oTransGeom.CreatePoint2d(0, 0), _
    oTransGeom.CreatePoint2d(4, 0))

    ' Because we need the sketch line in the context of the assembly
    ' we need to create a proxy for the sketch line. The proxy
    ' represents the sketch line in the context of the assembly.
    Dim oSketchLine1Proxy As Object
    oOcc1.CreateGeometryProxy(oSketchLine1, oSketchLine1Proxy)

    ' Create a sketch on the second part.
    Dim oSketch2 As PlanarSketch
    oSketch2 = oOcc2.Definition.Sketches.Add(oOcc2.Definition.WorkPlanes(1))

    ' Create a proxy for the sketch in the second part.
    Dim oSketch2Proxy As PlanarSketchProxy
    oOcc2.CreateGeometryProxy(oSketch2, oSketch2Proxy)

    ' Project the line in the sketch in the first
    ' part to the sketch in the second part
    Dim oSketchLine2Proxy As SketchLineProxy
    oSketchLine2Proxy = oSketch2Proxy.AddByProjectingEntity(oSketchLine1Proxy)

MessageBox.Show("next, remove the link", "remove projection")

If oSketchLine2Proxy.Reference Then
oSketch2Proxy.Adaptive = False
oSketchLine2Proxy.Reference = False
oSketchLine2Proxy.Delete
End If
oSketch2Proxy.Solve End Sub

and now the code works, but if you check the sketch, there is an error on the-cross-part-reference.

robbeRtek_0-1701082377783.png

robbeRtek_1-1701083659310.png

 

same issue in all inventor versions that i try (2019,2023,2024)...

 
 

@johnsonshiue
Can you give us an direction?
Many thanks.

 

0 Likes
Message 6 of 6

robbeRtek
Advocate
Advocate
the manual say this : https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-2CC87B13-2ED1-4052-AC8A-9B719907AA5B

so i try it with code, but no solution,

Public Sub Main()
	Dim Doc As Document
	If (ThisApplication.Documents.Count <> 0) Then
		Doc = ThisApplication.ActiveDocument
	Else
		MsgBox("There are no open documents!")
		Exit Sub
	End If
	Dim oTopNode As BrowserNode
	oTopNode = Doc.BrowserPanes("Model").TopNode

	' Create a collection to store references
	Dim references As New List(Of BrowserNode)
	references.Clear

	' Start the recursion and populate the references collection
	recurse(oTopNode, references)

	' Select the references and break the links
	Dim referencedef As BrowserNode
	For Each referencedef In references
		' Debug.Print(referenceItem)
		MessageBox.Show(referencedef.BrowserNodeDefinition.Label, "Title")

		' Ensure the sketch is in edit mode
		' Dim compOcc As ComponentOccurrence
		'  compOcc = referencedef.Parent.parent
		Dim sketchname As Object = referencedef.Parent
		Dim sketch As PlanarSketchProxy = sketchname.NativeObject

		'MessageBox.Show(sketch.BrowserNodeDefinition.Label, "Title")
		'sketch = compOcc.Definition.Sketches.Item(referencedef.BrowserNodeDefinition.Label)
		sketch.Edit

		' Break the link
		ThisDoc.Document.SelectSet.Clear
		referencedef.DoSelect
		MsgBox("xx")

		MsgBox(ThisDoc.Document.SelectSet.Count)
		ThisApplication.CommandManager.ControlDefinitions.Item("BreakLinkCmd").Execute
	Next referencedef
End Sub

Sub recurse(node As BrowserNode, ByRef references As List(Of BrowserNode))
	If (node.Visible = True) Then
		' Check if the label contains a reference (you may need to modify this condition)
		If InStr(node.BrowserNodeDefinition.Label, "Reference") > 0 Then
			' Add the reference to the collection
			references.Add(node)
		End If

		' Recursively process child nodes
		Dim bn As BrowserNode
		For Each bn In node.BrowserNodes
			Call recurse(bn, references)
		Next
	End If
End Sub

ThisApplication.CommandManager.ControlDefinitions.Item(BreakLinkCmd).Execute, do nothing 😞

0 Likes