ilogic: Change layer of part-sketch in drawing

ilogic: Change layer of part-sketch in drawing

c_stulz
Advocate Advocate
994 Views
2 Replies
Message 1 of 3

ilogic: Change layer of part-sketch in drawing

c_stulz
Advocate
Advocate

Hello,

here is my Idea I want to realise.

- I placed an Assambly on my drawing

- In one Part of the Assambly i switch a Sketch to visible

- Now I want A: switch this Sketch between visible or NonVosible with iLogic

SketchLayer_01.png

 

I have an sample, where I find this Sketch in Browsernodes:

Sub Main()
Dim oDrwDoc As DrawingDocument
	oDrwDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
    oSheet = oDrwDoc.ActiveSheet
Dim oBrowserPanes As BrowserPanes
	oBrowserPanes = oDrwDoc.BrowserPanes
Dim oBrowserNode As BrowserNode

	oBrowserNode = oBrowserPanes.Item(1).TopNode.BrowserNodes.Item(2).BrowserNodes.Item(3).BrowserNodes.Item(1).BrowserNodes.Item(7).BrowserNodes.Item(7)
	oBrowserNode.Visible = False	' makes only the BrowserNode Unvisible and not the sketch in Drawing
	'oBrowserNode.DoSelect			' select the Browsernode
End Sub

When I go to switch Visible = False Only the Browsernode will go to invisible.

With "oBrowserNode.DoSelect" I can select the BrowserNode, but I can't find a way to make the sketch invisible like I do it with the kontextmenue by my self.

 

Any Idea?

 

Greatings Christoph

 

 

0 Likes
Accepted solutions (1)
995 Views
2 Replies
Replies (2)
Message 2 of 3

c_stulz
Advocate
Advocate

Hello,

my second way I tried was to switch every Sketchline to an other Layer.

Sub Main()
' Define Variables
	Dim oDrwDoc As DrawingDocument
		oDrwDoc = ThisApplication.ActiveDocument

	Dim oSheet As Sheet
	    oSheet = oDrwDoc.ActiveSheet
	Dim oAsmDoc As AssemblyDocument = ThisDrawing.ModelDocument
	Dim oOcc As ComponentOccurrence
	Dim oOccs As ComponentOccurrences
		oOccs = oAsmDoc.ComponentDefinition.Occurrences
	Dim oPrtDef As ComponentDefinition
	Dim oSketches As PlanarSketches
	Dim oSketch As PlanarSketch
	Dim oSketchLines As SketchLines
	Dim oSketchLine As SketchLine
' Search first Sketchline in Sketch (later is used for all Lines)
	For Each oOcc In oOccs
		If oOcc.Name = "Test_BT:1" Then
			oPrtDef = oOcc.Definition
			oSketches = oPrtDef.Sketches
			oSketch = oSketches.Item(2)
			oSketchLines = oSketch.SketchLines
			oSketchLine = oSketchLines.Item(1)
		End If
	Next

' Get the needed DrawingView
	Dim oDrawViews As DrawingViews
	Dim oDrawView As DrawingView
	Dim oView As DrawingView
		For Each oDrawView In oSheet.DrawingViews	
			If oDrawView.Name = "ANSICHT1" Then
				oView = oDrawView
			End If
		Next

	' Search for DrawingCurve
        Dim oDrawCurve As DrawingCurve
		Dim oDrawViewCurves As DrawingCurvesEnumerator
			oDrawViewCurves = oView.DrawingCurves(oSketchLine)    ' ERROR: I think here is a SketchLineProxy nessesary  		
			oDrawCurve = oDrawViewCurves.Item(1)
		
		Dim oLayers As LayersEnumerator = oDrwDoc.StylesManager.Layers
		Dim oLayer As Layer = oLayers.Item("LayerRot")
		oDrawCurve.Segments.Item(1).Layer = oLayer
End Sub

 This Code based on a way I use Sketchlines for plasing dimensions. In that case I go and search the sketchlines wich has attributes.

The big different there is:

I search and get SketchLinieProxys insted of SketchLines.

And with the SketchlineProxys I get there allthough the equivalent DrawingCurve.

 

I apologize for my bad english and the bad explanation 😞

 

Greatings Christoph

0 Likes
Message 3 of 3

c_stulz
Advocate
Advocate
Accepted solution

So, I could find the missing step.

I had to make a SketchProxy by my one. Then I can set the Sketch(Proxy) Visible or not. Allthogh I can change the Layer of the Sketchlines.

 

Here is the sample:

Sub Main()
' Define Variables
	Dim oDrwDoc As DrawingDocument
		oDrwDoc = ThisApplication.ActiveDocument

	Dim oSheet As Sheet
	    oSheet = oDrwDoc.ActiveSheet
	Dim oAsmDoc As AssemblyDocument = ThisDrawing.ModelDocument
	Dim oOcc As ComponentOccurrence
	Dim oOccs As ComponentOccurrences
		oOccs = oAsmDoc.ComponentDefinition.Occurrences
	Dim oPrtDef As ComponentDefinition
	Dim oSketches As PlanarSketches
	Dim oSketch As PlanarSketch
	Dim oSketchProxy As PlanarSketchProxy
	Dim oSketchLines As SketchLines
	Dim oSketchLine As SketchLine
' Search first Sketchline in Sketch (later is used for all Lines)
	For Each oOcc In oOccs
		If oOcc.Name = "Test_BT:1" Then
			oPrtDef = oOcc.Definition
			oSketches = oPrtDef.Sketches
			oSketch = oSketches.Item(2)
			oOcc.CreateGeometryProxy(oSketch, oSketchProxy)
		End If
	Next

' Get the needed DrawingView
	Dim oDrawViews As DrawingViews
	Dim oDrawView As DrawingView
	Dim oView As DrawingView
		For Each oDrawView In oSheet.DrawingViews	
			If oDrawView.Name = "ANSICHT1" Then
				oView = oDrawView
			End If
		Next

	' Set Visibility of SketchProxy
		oView.SetVisibility(oSketchProxy, True)
	
	
	' Search for first DrawingCurve of SketchProxy to change Layer
        Dim oDrawCurve As DrawingCurve
		Dim oDrawViewCurves As DrawingCurvesEnumerator
			oDrawViewCurves = oView.DrawingCurves(oSketchProxy)    ' It works now with SketchProxy 
			oDrawCurve = oDrawViewCurves.Item(1)
		
		Dim oLayers As LayersEnumerator = oDrwDoc.StylesManager.Layers
		Dim oLayer As Layer = oLayers.Item("LayerRot")
		oDrawCurve.Segments.Item(1).Layer = oLayer
End Sub