Visibility in drawings environment

Visibility in drawings environment

kresh.bell
Collaborator Collaborator
743 Views
6 Replies
Message 1 of 7

Visibility in drawings environment

kresh.bell
Collaborator
Collaborator

Hi,

i have an iLogic for drawing environment, i want that when i run it, all the part with prefix "-" in solidbody name be hidden.

minus.jpg

 

Sub Main()

    Dim view As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select view")
    Dim assembly As AssemblyDocument = view.ReferencedDocumentDescriptor.ReferencedDocument

    For Each occ As ComponentOccurrence In assembly.ComponentDefinition.Occurrences
        Dim occDoc As Document = occ.Definition.Document
        If (occDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject) Then
            Dim partDoc As PartDocument = occDoc
            Dim name As String = partDoc.ComponentDefinition.SurfaceBodies.Item(1).Name
            If (name.StartsWith("-")) Then
                hideOccurence(view, occ)
            End If
        End If
    Next

End Sub

 

 

1) It doesn't work when those parts with prefix "-" are parts of assembly, is it possible to fix it?

2) it would be even better if it is possible to make iLogic in such a way that it in the drawing environment in the tree, controls "Visibility"

visibility1.jpg

 

now, iLogic controls the visibility lines in the drawing area, not in the tree

visibility2.jpg

0 Likes
744 Views
6 Replies
Replies (6)
Message 2 of 7

dutt.thakar
Collaborator
Collaborator

@kresh.bell 

Are you looking for something like this? I have added few lines, in the code which will search for the part documents inside the assembly, and if they start with "-", It will hide them.

 

Sub Main()

    Dim view As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select view")
    Dim assembly As AssemblyDocument = view.ReferencedDocumentDescriptor.ReferencedDocument

    For Each occ As ComponentOccurrence In assembly.ComponentDefinition.Occurrences
        Dim occDoc As Document = occ.Definition.Document
        If (occDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject) Then
            Dim partDoc As PartDocument = occDoc
            
			If occ.Name.StartsWith("-") Then
				 view.SetVisibility(occ,False)
			End If
			
			Dim name As String = partDoc.ComponentDefinition.SurfaceBodies.Item(1).Name
            If (name.StartsWith("-")) Then
                hideOccurence(view, occ)
            End If
			
        End If
    Next

End Sub

See if that works, if you need something more or different, please try to explain it in more detail.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 3 of 7

kresh.bell
Collaborator
Collaborator

unfortunately, something is not ok

 

error.jpg

0 Likes
Message 4 of 7

dutt.thakar
Collaborator
Collaborator

@kresh.bell 

The line that is giving error is not modified by me.

hideOccurrence is the same as it was in the code you initially posted, I think when you have copied the iLogic rule from the forum or from anywhere else, there must be a function/sub that is doing this operation.

 

I only added these lines in the existing code.

 

	If occ.Name.StartsWith("-") Then
		view.SetVisibility(occ,False)
	End If

 

If you still struggle to find something, revert here and I will see what I can do. 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 5 of 7

kresh.bell
Collaborator
Collaborator

something is wrong, still the same error

0 Likes
Message 6 of 7

dutt.thakar
Collaborator
Collaborator

@kresh.bell 

 

Try below code and see if that helps.

 

Sub Main()

    Dim view As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select view")
    Dim assembly As AssemblyDocument = view.ReferencedDocumentDescriptor.ReferencedDocument

    For Each occ As ComponentOccurrence In assembly.ComponentDefinition.Occurrences
        Dim occDoc As Document = occ.Definition.Document
        If (occDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject) Then
            Dim partDoc As PartDocument = occDoc
            
			If occ.Name.StartsWith("-") Then
				 view.SetVisibility(occ,False)
			End If
			
			Dim name As String = partDoc.ComponentDefinition.SurfaceBodies.Item(1).Name

			Dim obj As Object = partDoc.ComponentDefinition.SurfaceBodies.Item(1)
            If (name.StartsWith("-")) Then
                view.SetVisibility(obj,False)
            End If
			
        End If
    Next

End Sub
If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 7 of 7

WCrihfield
Mentor
Mentor

It's not really clear which of these you are trying to do:

- if component's name starts with "-" then turn it's visibility off

- if SurfaceBody's Name starts with "-" then just turn the visibility of that SurfaceBody off, but leave its component visible

- if component's first SurfaceBody's Name starts with "-" then turn the component's visibility off (but do nothing with the SurfaceBody)

 

If that SurfaceBody is the only SurfaceBody within the Part, then simply turning that SurfaceBody's visibility off should be enough.  Or if you simply turn the component's visibility off, that should be enough.  But turning both off seems like 'overkill'.

Here's a code that: 1) doesn't check the name of the component; 2) if the component is a Part, check if its first SurfaceBody's name starts with "-"; 3) if it does, try to turn that component's visibility off within the view; 4) if that fails, let you know.

Sub Main()
    Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select view")
	If oView Is Nothing Then Exit Sub
	Dim oADoc As AssemblyDocument
	If oView.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		oADoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
	End If
	Dim oPDoc As PartDocument
	For Each oOcc As ComponentOccurrence In oADoc.ComponentDefinition.Occurrences
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
            oPDoc = oOcc.Definition.Document
		End If
		If oPDoc.ComponentDefinition.SurfaceBodies.Item(1).Name.StartsWith("-") Then
			Try
				oView.SetVisibility(oOcc, False)
			Catch
				MsgBox("Failed while attempting to turn off visibility of component '" & oOcc.Name & "', within this view.",,"")
			End Try
		End If
    Next
End Sub

Other things to consider:

Does the DrawingView have a View Representation (other than "Master" set)?  If so, is the checkbox checked for "Associative"?  If 'Associative' is turned on, it likely won't let you change visibility of stuff within the view.  You may have to turn 'Associative' off before attempting to modify visibility of items within the view.

Do you have a 'Level of Detail' representation or a Position representation set for that DrawingView?

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes