visibility sketch in drawing - ilogic

visibility sketch in drawing - ilogic

Anonymous
Not applicable
1,665 Views
9 Replies
Message 1 of 10

visibility sketch in drawing - ilogic

Anonymous
Not applicable

HI all.

 

I need help with visibility sketch in drawing. This sketch I want to looking for  according to its name. This sketch it will be in sub assembly or part. Do you know how make it with using ilogic ??

Thanks for reply

0 Likes
Accepted solutions (1)
1,666 Views
9 Replies
Replies (9)
Message 2 of 10

LukeDavenport
Collaborator
Collaborator

Hi Johny,

Here's a blog that covers this topic, with some example code.

Hope it's useful

Luke

 

https://www.excitech.co.uk/Insights/Blog/December-2017/Autodesk-Inventor-2018-iLogic-Control-Model-S...

0 Likes
Message 3 of 10

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

Try this code. Define the name of the sketch at the first line, then when the code is running - pick the drawing view in which you want to set the sketch to visible.

 

The code has edits since first posted

 

Sub Main
	Dim sketchName As String = "Sketch1" 'Name of sketch
	Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select Drawing view")

	If oView Is Nothing Then Exit Sub

	Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
	
	If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
		For Each oSketch As PlanarSketch In oDoc.ComponentDefinition.Sketches
			If oSketch.Name = sketchName
				oView.SetVisibility(oSketch, True)
			End If
		Next
		For Each orefDoc As Document In oDoc.AllReferencedDocuments
			If orefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject _
				Or orefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
				Try
				Dim oSketch As PlanarSketch = orefDoc.ComponentDefinition.Sketches.Item(sketchName)
				For Each oOcc As ComponentOccurrence In oDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(orefDoc)
					Dim sketchToInclude = CreateSketchProxy(oOcc.OccurrencePath, oSketch.Name)
					oView.SetVisibility(sketchToInclude, True)
				Next
				Catch
				End Try
			End If
		Next

	ElseIf oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
		For Each oSketch As PlanarSketch In oDoc.ComponentDefinition.Sketches
			If oSketch.Name = sketchName
				oView.SetVisibility(oSketch, True)
			End If
		Next
	End If
End Sub

Function CreateSketchProxy(oOccList As ComponentOccurrencesEnumerator, oSketchName As String) As Object
	Dim oProx As Object
	For i = oOccList.Count To 1 Step -1
		If i = oOccList.Count
			Call oOccList(i).CreateGeometryProxy(oOccList(i).Definition.Sketches.Item(oSketchName), oProx)
		Else
			Call oOccList(i).CreateGeometryProxy(oProx, oProx)
		End If

	Next
	Return oProx
End Function

 

Message 4 of 10

Anonymous
Not applicable

Hi,

 

I tried your code and it show me "error on line 1 and 38 line" - The command is not valid in the namespace. these lines are Sub main and end sub. Do you know what is means?

0 Likes
Message 5 of 10

Anonymous
Not applicable

Hi,

 

I know this link. But first I need turn on visibility using sketch name.. and than is problem that when I turn off visibility of subassembly/part where is sketch this rule doesn´t work.
I tried understand this code and applicate on my problem but.... with this languageI have more problems than with English 😄

0 Likes
Message 6 of 10

JhoelForshav
Mentor
Mentor

@Anonymous 

Thats strange... The only thing i can think of is to maybe change "Sub Main" to "Sub Main()"

0 Likes
Message 7 of 10

Anonymous
Not applicable

This I tried.... and the same error..

0 Likes
Message 8 of 10

JhoelForshav
Mentor
Mentor

I dont know what to tell you... I've never experienced that error in an iLogic rule...

You don't have Straight VB code checked, right?

straightVB.PNG

Message 9 of 10

Anonymous
Not applicable

Yes. I had turn on straight VB code.

Now this code run! 😏

0 Likes
Message 10 of 10

Anonymous
Not applicable

Thank you.

0 Likes