If work features/sketches are visible, then prompt to turn off?

If work features/sketches are visible, then prompt to turn off?

steveh3
Advisor Advisor
498 Views
6 Replies
Message 1 of 7

If work features/sketches are visible, then prompt to turn off?

steveh3
Advisor
Advisor

I know there is a way to have a dialog box to pop up and ask question to turn on/off work features and works good. I would like to take this a step further and only have the pop up show when work features and or sketches are visible. if they aren't, the dialog box never appears.

 

Possible with iLogic?

 

Thanks in advance,

 

Steve H.

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Accepted solutions (1)
499 Views
6 Replies
Replies (6)
Message 2 of 7

Michael.Navara
Advisor
Advisor

It is your own dialog? In this case you can check all work features and sketches, select all visible and if any, then show the dialog. Later on, you can iterate only visible and turn them off.

 

0 Likes
Message 3 of 7

steveh3
Advisor
Advisor

Most of it is not or maybe all of it. Can't remember if I tweaked it or not.

Initially I had it set up to run every time a save happened, but that was to much. Then in 2023 I added it to ribbon for users to hit, but now, they just ignore it or forget about it.

So, my last thought is....if a work feature / sketch is visible then activate the prompt.....

Here's the code....

Sub Main()
    'user feedback tools start
    Dim sw As New Stopwatch()
    sw.Start()
    'get user input as True or False
    Dim Assyboolean As Boolean = InputRadioBox("Turn all Work Features On/Off", "On", "Off", False, "iLogic")

    If ThisApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
        ToggleParts(ThisApplication.ActiveDocument, Assyboolean)
    ElseIf ThisApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
        'Dim wfBoolean As Boolean = InputRadioBox("Turn all Work Features & Sketches On/Off", "On", "Off", False, "iLogic")
        ToggleAssemblies(ThisApplication.ActiveDocument, Assyboolean)
    End If
    sw.Stop()
    Dim timeElapsed As TimeSpan = sw.Elapsed
'    MessageBox.Show("Processing took: " & String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
'                                                        timeElapsed.Hours,
'                                                        timeElapsed.Minutes,
'                                                        timeElapsed.Seconds,
'                                                        timeElapsed.Milliseconds / 10))
End Sub

Sub ToggleAssemblies(ByVal oAssyDoc As AssemblyDocument, ByVal wfBoolean As Boolean)
    'Toggle this document
    'set work plane visibility
    For Each oWorkPlane In oAssyDoc.ComponentDefinition.WorkPlanes
        oWorkPlane.Visible = wfBoolean
    Next

    'set work axis visibility
    For Each oWorkAxis In oAssyDoc.ComponentDefinition.WorkAxes
        oWorkAxis.Visible = wfBoolean
    Next

    'set work point visibility
    For Each oWorkPoint In oAssyDoc.ComponentDefinition.WorkPoints
        oWorkPoint.Visible = wfBoolean
    Next
    'Check all referenced docs
    Dim oDoc As Inventor.Document
    For Each oDoc In oAssyDoc.AllReferencedDocuments
        If TypeOf oDoc Is PartDocument Then
            ToggleParts(oDoc, wfBoolean)
        Else
            'set work plane visibility
            For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
                oWorkPlane.Visible = wfBoolean
            Next

            'set work axis visibility
            For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxes
                oWorkAxis.Visible = wfBoolean
            Next

            'set work point visibility
            For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
                oWorkPoint.Visible = wfBoolean
            Next
            ToggleAssemblies(oDoc, wfBoolean)
        End If
    Next
    'update the files
    InventorVb.DocumentUpdate()
End Sub

Sub ToggleParts(ByVal oDoc As Document, ByVal wfBoolean As Boolean)
    Dim PartDoc As PartDocument = oDoc
    ''get user input as True or False
    '    Dim partboolean As Boolean = Nothing
    '    If wfBoolean = Nothing Then
    '        partboolean = InputRadioBox("Turn all Work Features On/Off", "On", "Off", False, "iLogic")
    '    Else
    '        partboolean = wfBoolean
    '    End If
    For Each oWorkPlane In PartDoc.ComponentDefinition.WorkPlanes
        oWorkPlane.Visible = wfBoolean
    Next
    'set work axis visibility
    For Each oWorkAxis In PartDoc.ComponentDefinition.WorkAxes
        oWorkAxis.Visible = wfBoolean
    Next
    'set work point visibility
    For Each oWorkPoint In PartDoc.ComponentDefinition.WorkPoints
        oWorkPoint.Visible = wfBoolean
    Next
    togglePartSketches(oDoc, wfBoolean)
    InventorVb.DocumentUpdate()
End Sub

Sub togglePartSketches(ByVal doc As Document, ByVal wfBoolean As Boolean)
    For Each o2DSketch As Sketch In doc.ComponentDefinition.Sketches
        o2DSketch.Visible = wfBoolean
    Next

    For Each o3DSketch As Sketch3D In doc.ComponentDefinition.Sketches3D
        o3DSketch.Visible = wfBoolean
    Next

    'wfBoolean = InputRadioBox("Toggle Sketch Dimension display On/Off", "On", "Off", False, "iLogic")
    For Each o2DSketch As Sketch In doc.ComponentDefinition.Sketches
        o2DSketch.DimensionsVisible = wfBoolean
    Next
End Sub
Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

Hi @steveh3.  Since you used to have this launch on save, do you plan on making a rule like this launch on save again, or on some other event?  When using save event, then I recommend on before save (instead of after save), then do not include saving within the code, because it will be saved afterwards, and you do not wand to cause endless loop.  I see lots of potential to greatly condense your code, too.  You could potentially ignore document type, to use the same sub routine for both document types, especially if running on all referenced documents.  But if looping through components, which have their own DVR (DesignViewRepresentation) settings, you could simply make the one routine recursive (calls itself again, if sub components are present, to go the next step deeper each time), instead of repeating code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

steveh3
Advisor
Advisor

Plan on triggering it on a save as suggested. It would check to see if work features and/or sketches are visible. If so, it would prompt to turn them off or do nothing and leave them on.

Best,

Steve H.

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Hi @steveh3.  I have something here for you to check out.  It does not contain much error handling yet, and I have not test ran this yet, but I think it should be a fairly good step in the right direction.  Messing around with the visibility of stuff throughout the structure of an assembly can be complex & messy business, because all of the component objects themselves can be set to different DesignViewRepresentations (and they may be set to 'Associative').  And we haven't even touched on the whole ModelStates thing yet, which complicates your document references.  I put a line in the Function to avoid attempting to make changes to documents if they are not 'modifiable', such as Content Center stuff, iPart/iAssembly, Library files, etc).  But since it just deals with referenced documents, it does not do anything with component DVR settings at this time.  It could be changed to loop components recursively, or expanded/improved in other ways too, if needed.

 

Sub Main
	Dim oDoc As Document = ThisDoc.Document
	If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
	Dim oAllRefDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments
	Dim MainDocHasVisibleStuff, RefDocsHaveVisibleStuff As Boolean 'False by default
	MainDocHasVisibleStuff = CheckVisibility(oDoc)
	If oAllRefDocs.Count > 0 Then
		For Each oRefDoc As Document In oAllRefDocs
			If CheckVisibility(oRefDoc) Then RefDocsHaveVisibleStuff = True
		Next
	End If
	If MainDocHasVisibleStuff Or RefDocsHaveVisibleStuff Then
		Dim oAns As MsgBoxResult = MsgBox("Some Sketches or Work Features are visible." & vbCrLf & _
		"Do you want to turn them all off?", vbYesNo + vbQuestion, "Visibility Check")
		If oAns = MsgBoxResult.No Then Exit Sub
		If MainDocHasVisibleStuff Then CheckVisibility(oDoc, True) 'True will turn off visibility
		If RefDocsHaveVisibleStuff Then
			For Each oRefDoc As Document In oAllRefDocs
				CheckVisibility(oRefDoc, True) 'True will turn off visibility
			Next
		End If
		If oDoc.RequiresUpdate Then oDoc.Update2(True)
	End If
End Sub

'can be used to just 'check' if any are visible, or to turn visibility off, if second input is True
Function CheckVisibility(oDoc As Document, Optional TurnAllOff As Boolean = False) As Boolean
	'should return True to calling routine, if any of these was found to be Visible
	If TurnAllOff And (oDoc.IsModifiable = False) Then Return False 'can't make changes to this oDoc
	'you may need to deal with DesignViewRepresentations, to save any changes
	Dim oWPlanes As WorkPlanes = oDoc.ComponentDefinition.WorkPlanes
	Dim oWAs As WorkAxes = oDoc.ComponentDefinition.WorkAxes
	Dim oWPts As WorkPoints = oDoc.ComponentDefinition.WorkPoints
	Dim oPSketches As PlanarSketches = oDoc.ComponentDefinition.Sketches
	Dim oSketches3D As Sketches3D = Nothing 'only in parts, not in assemblies
	If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		oSketches3D = oDoc.ComponentDefinition.Sketches3D
		For Each oSketch3D As Sketch3D In oSketches3D
			If oSketch3D.Visible Then If TurnAllOff Then oSketch3D.Visible = False Else Return True
		Next
	End If
	For Each oWPlane As WorkPlane In oWPlanes
		If oWPlane.Visible Then If TurnAllOff Then oWPlane.Visible = False Else Return True
	Next
	For Each oWA As WorkAxis In oWAs
		If oWA.Visible Then If TurnAllOff Then oWA.Visible = False Else Return True
	Next
	For Each oWPt As WorkPoint In oWPts
		If oWPt.Visible Then If TurnAllOff Then oWPt.Visible = False Else Return True
	Next
	For Each oPSketch As PlanarSketch In oPSketches
		If oPSketch.Visible Then If TurnAllOff Then oPSketch.Visible = False Else Return True
	Next
	Return False
End Function

 

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
Message 7 of 7

steveh3
Advisor
Advisor

Thanks @WCrihfield ....

I will take a look at this code and see how it works.

Best,

Steve H.

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes