Suppressing welds

Suppressing welds

dbushDQ3RE
Participant Participant
2,951 Views
33 Replies
Message 1 of 34

Suppressing welds

dbushDQ3RE
Participant
Participant

Does anyone out there know of a faster (more efficient) way to suppress welds (single or multiple) then my example.

 

Sub Main
' Get the active assembly.
Dim doc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

'REPLACE ITEM
SuppressWeldBead()
InventorVb.DocumentUpdate()
iLogicVb.UpdateWhenDone = True
End Sub


Enum SuppressOption
  kSuppress
  kUnsuppress
  kToggle
End Enum

Sub SuppressBead( _
wcd As WeldmentComponentDefinition, _
wbn As BrowserNode, _
so As SuppressOption)
  Dim name As String
  name = wbn.BrowserNodeDefinition.Label


  ' We only need to check the current state of the bead if
  ' we are not just toggling its state but want a specific one
  If so <> kToggle Then
    ' If the bead is already suppressed then its
    ' BeadFaces.Count will be 1
    Dim bfs As Faces
    bfs = wcd.Welds.WeldBeads(name).BeadFaces
    If bfs.Count = 1 Xor so = kUnsuppress Then Exit Sub
  End If
  
  ' Get the CommandManager object
  Dim cm As CommandManager
  cm = ThisApplication.CommandManager
  
  ' Get the collection of control definitions
  Dim cds As ControlDefinitions
  cds = cm.ControlDefinitions
      
  ' Run the "Suppress" command
  ThisApplication.SilentOperation = True
  Call wbn.DoSelect
  Call cds("AssemblySuppressFeatureCtxCmd").Execute2(True)
  ThisApplication.SilentOperation = False
End Sub

Sub SuppressWeldBead()
  Dim weldName As String
  weldName = "Fillet Weld 78"

  ' Get document
  Dim doc As AssemblyDocument
  doc = ThisApplication.ActiveDocument
  
  Dim wcd As WeldmentComponentDefinition
  wcd = doc.ComponentDefinition
 
  ' Get "Model" browser
  Dim bp As BrowserPane
  bp = doc.BrowserPanes("AmBrowserArrangement")
  
  ' Get "Welds" node
  Dim wbn As BrowserNode
  For Each wbn In bp.TopNode.BrowserNodes
    If wbn.BrowserNodeDefinition.Label = "Welds" Then
      Exit For
    End If
  Next
 
  ' Get "Beads" node
  Dim bbn As BrowserNode
  For Each bbn In wbn.BrowserNodes
    If bbn.BrowserNodeDefinition.Label = "Beads" Then
      Exit For
    End If
  Next
  
 Dim timeout = 3 ' secs

TimeSpan.FromSeconds(timeout)

  ' Get the Beads we want to suppress
  For Each wbn In bbn.BrowserNodes

    If wbn.BrowserNodeDefinition.Label = weldName Then
      Call SuppressBead(wcd, wbn, kSuppress)
    End If
  Next
End Sub

 

0 Likes
Accepted solutions (1)
2,952 Views
33 Replies
Replies (33)
Message 2 of 34

WCrihfield
Mentor
Mentor

You can check to see if using this process would be any faster than executing the command for each weld bead you want to suppress.  This process uses an ObjectCollection, and the WeldComponentDefinition.SuppressFeatures() sub.  So if you had a list of weld bead names that you want to suppress, you could check if each browser node's definition label matched any of the names in the list, and if it does, you could add it to the collection.  Or if you have other criteria to identify the weld beads you want to suppress, you could use those checks, to filter which ones get added to the collection.  Then pass that collection to the SuppressFeatures process mentioned above in one step.

Or, I suppose you could simply loop through the WeldComponentDefinition.Welds directly, while checking the oWeld.Name against the ones in your list (or individual name(s)), then add them to the collection.

This sounds like it ought to be faster than executing a command on each weld bead individually.

 

 

 

 

 

Sub Main
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	SuppressWeldBead(oADoc)
	InventorVb.DocumentUpdate()
End Sub

Enum SuppressOption
	kSuppress
	kUnsuppress
	kToggle
End Enum

Sub SuppressWeldBead(ByRef oAsmDoc As AssemblyDocument)
	Dim oWDef As WeldmentComponentDefinition = oAsmDoc.ComponentDefinition
	Dim oPane As BrowserPane = oAsmDoc.BrowserPanes("AmBrowserArrangement") 'Model Browser Pane
	'Dim oBeadNames As New List(Of String)
	'oBeadNames.Add("Fillet Weld 78")
	Dim oBeads As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	Dim oBead As WeldBead
	Dim oWNode, oWBNode, oBNode As BrowserNode
	For Each oWNode In oPane.TopNode.BrowserNodes 'Get Welds node
		If oWNode.BrowserNodeDefinition.Label = "Welds" Then
			For Each oWBNode In oWNode.BrowserNodes 'Get Beads node
				If oWBNode.BrowserNodeDefinition.Label = "Beads" Then
					'System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3)) 'not sure why you would need to wait here
					For Each oBNode In oWBNode.BrowserNodes ' Get the Beads we want to suppress
						'For Each oWBName As String In oBeadNames
						If oBNode.BrowserNodeDefinition.Label = "Fillet Weld 78" Then
							If TypeOf oBNode.NativeObject Is Inventor.WeldBead Then
								oBead = oBNode.NativeObject
								oBeads.Add(oBead)
								oWDef.SuppressFeatures(oBeads)
							End If
							'Call SuppressBead(oWDef, oBNode, kSuppress)
						End If
					Next
				End If
			Next
		End If
	Next
End Sub

'Sub SuppressBead(oWDef As WeldmentComponentDefinition,oNode As BrowserNode,oSO As SuppressOption)
'	Dim oName As String = oNode.BrowserNodeDefinition.Label
'	' We only need to check the current state of the bead if we are not just toggling its state but want a specific one
'	If oSO <> kToggle Then
'    ' If the bead is already suppressed then its BeadFaces.Count will be 1
'		If oWDef.Welds.WeldBeads(oName).BeadFaces.Count = 1 Xor oSO = kUnsuppress Then Exit Sub
'	End If
'	ThisApplication.SilentOperation = True
'	Call oNode.DoSelect
'	Call ThisApplication.CommandManager.ControlDefinitions("AssemblySuppressFeatureCtxCmd").Execute2(True)
'	ThisApplication.SilentOperation = False
'End Sub

 

 

 

 

 

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

Vote For My IDEAS 💡 and Explore My CONTRIBUTIONS

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 34

WCrihfield
Mentor
Mentor

Oddly enough, navigating to the weld bead through the Browser Pane and using the executing that command, does appear to be the only way to do it.

Selection:

In my attempts to bypass the Browser Pane route, and just find the weld bead through normal means, I am definitely finding the weld bead I am looking for, but none of the selection procedures will work on it.  I've tried using the SelectSet.Select(oWeldBead) method, and that always throws an error, making it seem like that Sub doesn't recognize that object.  It doesn't matter if I have looped through the oWeldDef.Welds and defined the object as a Weld object, or if I have looped through the oWeldDef.Welds.WeldBeads, and have defined the object as a WeldBead object.  It won't select it using the SelectSet.Select() (yes I know how to use it, and have for years).  I have also tried the browser node's DoSelect process, without navigating to the node, by using the oBrowserPane.GetBrowserNodeFromObject(oWeldBead) process, but that Get function always throws an error too, no matter which object I supplied it.  So the only way I was able to select the weld was to navigate the BrowserPane (as in the original post) to get that BrowserNode then use its DoSelect.

Suppression:

And, no matter which way I approached it, the built-in oWeldDef.SuppressFeatures() method would not accept any variation of Welds or WeldBeads (even when put into an ObjectCollection), as the input variable.  It always throws errors.  It must only recognize simple PartFeature type features.

 

So, in conclusion, I had to navigate the Browser Pane.  I had to use the BrowserNode's DoSelect.  And I had to execute the command to suppress the weld.  However, there may still be a way to select multiple browser nodes for multiple welds, then just execute the command once, if needed, because you can do this manually.  So there may be some room for improvement. 😅

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
		ThisApplication.ActiveDocument.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value <> "Weldment" Then
		MsgBox("This rule only works on Weldment Assembly documents. Exiting.", vbOKOnly, " ")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oWDef As WeldmentComponentDefinition = oADoc.ComponentDefinition
	Dim oPane As BrowserPane = oADoc.BrowserPanes("AmBrowserArrangement") 'Model Browser Pane
	Dim oWNode, oWBNode, oBNode As BrowserNode
	For Each oWNode In oPane.TopNode.BrowserNodes 'Get Welds node
		If oWNode.BrowserNodeDefinition.Label = "Welds" Then
			For Each oWBNode In oWNode.BrowserNodes 'Get Beads node
				If oWBNode.BrowserNodeDefinition.Label = "Beads" Then
					For Each oBNode In oWBNode.BrowserNodes ' Get the Beads we want to suppress
						If oBNode.BrowserNodeDefinition.Label = "Fillet Weld 78" Then
							oBNode.DoSelect
						End If
					Next
				End If
			Next
		End If
	Next
	ThisApplication.CommandManager.ControlDefinitions.Item("AssemblySuppressFeatureCtxCmd").Execute2(True)
End Sub

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

Vote For My IDEAS 💡and Explore My CONTRIBUTIONS

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 34

dbushDQ3RE
Participant
Participant
 

WCrihfield,

Thanks for the advice,

However I have one last question concerning this operation. This rule runs and works most of the the time, However intermittently it ask for a selection which makes no sense. When it doesn"t ask for a selection all works. Any thoughts

 

 

0 Likes
Message 5 of 34

WCrihfield
Mentor
Mentor

In theory, if it didn't find a weld bead with the specified name, it then wouldn't have anything selected when the Suppress command was executed, and therefore is asking you for what feature(s) you want it to suppress.  The first thing I would suggest is to move that line of code that executes the command up to right after the  "oBNode.DoSelect" line.  Then, it would only execute the suppress command if the conditions of that If...Then check were met.  In my last post I was hoping I could get the DoSelect sub to act similarly to the [Ctrl + Select], which would add each selection to a set of selected objects, but It simply won't work that way.  I also tried adding each matching BrowserNode to an ObjectCollection, then supplying that ObjectCollection to the SelectSet.SelectMultiple() near the end just before executing the suppress command, but that won't work either.  It seems there is no way to bundle multiple BrowserNode objects, or multiple WeldBead objects, or multiple Weld objects, into a group which can all be acted upon at once by only executing the suppress command one time.  The only way I can get it to work is individually.  Very odd, and annoying, since it can be done manually.

   Here's the updated code:  (this version is working on my machine)

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
		ThisApplication.ActiveDocument.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value <> "Weldment" Then
		MsgBox("This rule only works on Weldment Assembly documents. Exiting.", vbOKOnly, " ")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oWDef As WeldmentComponentDefinition = oADoc.ComponentDefinition
	
	Dim oBeadNames As New List(Of String)
	'<<<<< UPDATE THESE NAMES >>>>>
	oBeadNames.Add("Fillet Weld 78")
'	oBeadNames.Add("Fillet Weld 5")
'	oBeadNames.Add("Fillet Weld 4")
'	oBeadNames.Add("Groove Weld 6")
	
	Dim oPane As BrowserPane = oADoc.BrowserPanes("AmBrowserArrangement") 'Model Browser Pane
	Dim oWNode, oWBNode, oBNode As BrowserNode
	For Each oWNode In oPane.TopNode.BrowserNodes 'Get Welds node
		If oWNode.BrowserNodeDefinition.Label = "Welds" Then
			For Each oWBNode In oWNode.BrowserNodes 'Get Beads node
				If oWBNode.BrowserNodeDefinition.Label = "Beads" Then
					For Each oBNode In oWBNode.BrowserNodes ' Get the Beads we want to suppress
						For Each oName As String In oBeadNames
							If oBNode.BrowserNodeDefinition.Label = oName Then
								oBNode.DoSelect
								ThisApplication.CommandManager.ControlDefinitions.Item("AssemblySuppressFeatureCtxCmd").Execute2(True)
							End If
						Next
					Next
				End If
			Next
		End If
	Next
End Sub

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

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 34

dbushDQ3RE
Participant
Participant

WCrihfield ,

Found one thing, that need fixed Instead of " beads " it "beads (All)". then the suppress worked well. Now I can find the unsuppress command to reverse the process. any thoughts!!!

0 Likes
Message 7 of 34

WCrihfield
Mentor
Mentor

Actually, I believe that command "AssemblySuppressFeatureCtxCmd" toggles assembly feature suppression.  So I believe you should  be able to use the same command to Suppress and to UnSuppress assembly features.  The same is true for the assembly component suppression command "AssemblyCompSuppressionCtxCmd".  It toggles component suppression, instead of just one way.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 34

dbushDQ3RE
Participant
Participant
Accepted solution

Thanks you Sir.

 Don't know how I missed the obvious. True or false is correct.  

0 Likes
Message 9 of 34

dbushDQ3RE
Participant
Participant

WCrihfield,

Still having an issue With this software asking for a selection one time and not the next. Would be great if we could connect on skype one time so I can show you what I:m dealing with. dbush

0 Likes
Message 10 of 34

mat_hijs
Collaborator
Collaborator

This code seems to work well, but I'm wondering if it's also possible to see if the weld bead is suppressed or not before running the command? Ultimately I want to set the suppression state either to true or false, even when I "don't know" what the current state is.

0 Likes
Message 11 of 34

WCrihfield
Mentor
Mentor

Hi @mat_hijs.  I do not believe that would be possible, because the BrowserNode object itself does not have any Properties for getting or setting their suppression status, and also the WeldWeldBead, & CosmeticWeld objects to not have any properties for that either.  I believe what we can see in the user interface, in the right-click menu, when we right-click on weld beads, is the following two common Inventor API methods.

SuppressFeatures 

UnsuppressFeatures 

We can likely use those two API methods, instead of selecting them, then executing a ControlDefinition command on the selection set.  When using those API methods, we would navigate the weldment type assembly's object model down to where the WeldBeads are, gather the ones we want to change/control into an ObjectCollection, then supply that ObjectCollection to the method to change their suppression state.  Those will not tell you what their previous / current state was though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 12 of 34

mat_hijs
Collaborator
Collaborator

@WCrihfieldIt seems that it was possible to do this after all, I found this link that explains it: Run command on browser item - Manufacturing DevBlog (typepad.com)

 

Here is what I made of that so it's easy for me to reuse, the True/False argument would be a parameter in my case.

Sub Main
	WeldSuppression("Weld1", True)
	WeldSuppression("Weld2", False)
End Sub

Public Sub WeldSuppression(ByVal sWeldName As String, ByVal bSuppressed As Boolean)
	' Set a reference to the Assembly Document
	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
	
	' Set a reference to the Assembly Component Definition
	Dim oAsmCompDef As WeldmentComponentDefinition = oAsmDoc.ComponentDefinition
	
	' Set a reference to the Model Browser Pane
	Dim oModelBrowserPane As BrowserPane = oAsmDoc.BrowserPanes("AmBrowserArrangement")
	
	' Set a reference to the Welds Browser Node
	Dim oWeldsBrowserNode As BrowserNode
	For Each oWeldsBrowserNode In oModelBrowserPane.TopNode.BrowserNodes
		If oWeldsBrowserNode.BrowserNodeDefinition.Label = "Welds" Then
			Exit For
		End If
	Next
	
	' Set a reference to the Beads Browser Node
	Dim oBeadsBrowserNode As BrowserNode
	For Each oBeadsBrowserNode In oWeldsBrowserNode.BrowserNodes
		If oBeadsBrowserNode.BrowserNodeDefinition.Label = "Beads" Then
			Exit For
		End If
	Next
	
	' Get the Beads we want to suppress
	For Each oWeldBrowserNode In oBeadsBrowserNode.BrowserNodes
		If oWeldBrowserNode.BrowserNodeDefinition.Label = sWeldName Then
			' Get the Bead Faces Count
			Dim iBeadFacesCount As Integer = oAsmCompDef.Welds.WeldBeads(sWeldName).BeadFaces.Count
			
			Select Case True
				Case bSuppressed = True And iBeadFacesCount > 0
					' Bead needs to be suppressed
				Case bSuppressed = False And iBeadFacesCount = 0
					' Bead needs to be unsuppressed
				Case Else
					' Suppression state is already correct
					Exit Sub
			End Select
			
			' Get the Command Manager
			Dim oCommandManager As CommandManager = ThisApplication.CommandManager
			
			' Get the Control Definitions
			Dim oControlDefinitions As ControlDefinitions = oCommandManager.ControlDefinitions
			
			' Enable Silent Operation to avoid getting a warning message
			ThisApplication.SilentOperation = True
			
			' Select the 
			oWeldBrowserNode.DoSelect
			
			' Run the "Suppress" command
			oControlDefinitions("AssemblySuppressFeatureCtxCmd").Execute2(True)
			
			' Disable Silent Operation
			ThisApplication.SilentOperation = False
		End If
	Next
End Sub

Message 13 of 34

WCrihfield
Mentor
Mentor

I'm glad you found a working solution.  Checking the 'Count' of their faces was a good idea for an alternate way of checking suppression status.  I was thinking that we could have avoided navigating the model browser tree altogether though, in favor of the process I described in the last part of my last response.  But, it does not really matter that much how you get there I guess, as long as you get there.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 14 of 34

tom89Y38
Enthusiast
Enthusiast

Hi @mat_hijs ,

 

I tried to adapt the rule to run it from a main assembly, search for the correct Weld Assembly and then try to suppress the weld.

I'm sure that the "GetWeldAssy" function works.

But when running the rule I get this pointer tip. Are you (or someone else) able to help me with this?

tom89Y38_0-1715864391147.png

 

 

WeldSuppression(GetWeldAssy(ThisApplication.ActiveDocument, "test2"), "MijnLas", False)

 

' Recursive search function
Function GetWeldAssy(ByVal oAssyDoc As AssemblyDocument, ByVal name As String) As AssemblyDocument
	For Each oComponent As ComponentOccurrence In oAssyDoc.ComponentDefinition.Occurrences
		' Check if the current component has the custom name in the browser node name
		If oComponent.Name = name Then
			' Check if it is a weld assembly
			Dim oCompDef As ComponentDefinition = oComponent.Definition
			If oCompDef.Type = kWeldmentComponentDefinitionObject Then
				'foundAssembly = oComponent.ReferencedDocumentDescriptor.ReferencedDocument
				foundAssembly = TryCast(oComponent.Definition.Document, AssemblyDocument)
				Return foundAssembly
				Exit Function
			End If
		End If

		' Recursively search in sub-components
		For Each subComponent As ComponentOccurrence In oComponent.SubOccurrences
			Dim foundInSubComponent As AssemblyDocument = GetWeldAssy(TryCast(oComponent.Definition.Document, AssemblyDocument), name)
			If Not foundInSubComponent Is Nothing Then
				Return foundInSubComponent
				Exit Function

			End If
		Next
	Next
End Function

Public Sub WeldSuppression(ByVal oWeldAssyDoc As AssemblyDocument, ByVal sWeldName As String, ByVal bSuppressed As Boolean)
	' Set a reference to the Assembly Document
	'Dim oWeldAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument

	' Set a reference to the Assembly Component Definition
	Dim oAsmCompDef As WeldmentComponentDefinition = oWeldAssyDoc.ComponentDefinition

	' Set a reference to the Model Browser Pane
	Dim oModelBrowserPane As BrowserPane = oWeldAssyDoc.BrowserPanes("AmBrowserArrangement")

	' Set a reference to the Welds Browser Node
	Dim oWeldsBrowserNode As BrowserNode
	For Each oWeldsBrowserNode In oModelBrowserPane.TopNode.BrowserNodes
		If oWeldsBrowserNode.BrowserNodeDefinition.Label = "Welds" Then
			Exit For
		End If
	Next

	' Set a reference to the Beads Browser Node
	Dim oBeadsBrowserNode As BrowserNode
	For Each oBeadsBrowserNode In oWeldsBrowserNode.BrowserNodes
		If oBeadsBrowserNode.BrowserNodeDefinition.Label = "Beads" Then
			Exit For
		End If
	Next

	' Get the Beads we want to suppress
	For Each oWeldBrowserNode In oBeadsBrowserNode.BrowserNodes
		If oWeldBrowserNode.BrowserNodeDefinition.Label = sWeldName Then
			' Get the Bead Faces Count
			Dim iBeadFacesCount As Integer = oAsmCompDef.Welds.WeldBeads(sWeldName).BeadFaces.Count

			Select Case True
				Case bSuppressed = True And iBeadFacesCount > 0
					' Bead needs to be suppressed
				Case bSuppressed = False And iBeadFacesCount = 0
					' Bead needs to be unsuppressed
				Case Else
			' Suppression state is already correct
			Exit Sub
			End Select

			' Get the Command Manager
			Dim oCommandManager As CommandManager = ThisApplication.CommandManager

			' Get the Control Definitions
			Dim oControlDefinitions As ControlDefinitions = oCommandManager.ControlDefinitions

			' Enable Silent Operation to avoid getting a warning message
			ThisApplication.SilentOperation = True

			' Select the 
			oWeldBrowserNode.DoSelect

			' Run the "Suppress" command
			oControlDefinitions("AssemblySuppressFeatureCtxCmd").Execute2(True)

			' Disable Silent Operation
			ThisApplication.SilentOperation = False
			End If
	Next
End Sub

 

0 Likes
Message 15 of 34

mat_hijs
Collaborator
Collaborator

The problem is that it's not actually selecting the browsernodes. Then you run the AssemblySuppressFeatureCtxCmd command without anything selected which causes the pointer you get. My guess would be that you might be able to get it working either opening the weldment separately or using edit.

0 Likes
Message 16 of 34

tom89Y38
Enthusiast
Enthusiast

Thanks for your quick reply.

I was thinking the same. Probably I need to do an "edit in place" and then run your code.

I never used a edit in place in iLogic, do you know how?

 

Thanks!

0 Likes
Message 17 of 34

WCrihfield
Mentor
Mentor

Hi guys.  Just an additional thought to keep in mind, but as you may recall, when working within a weldment type assembly, it has multiple edit modes.  One mode is the normal assembly mode, one is for editing welds, one is for editing weld preparations, and one is for machining.  In a case like this, you might possibly need to be in its mode for editing its welds...not sure.  To get that weldment assembly into that mode by code, you can use the following:

Welds.Edit 

Welds.ExitEdit 

Same for components... 

ComponentOccurrence.Edit 

ComponentOccurrence.ExitEdit 

...and when in edit mode of a component within an assembly, you can get a direct reference to that referenced document using the following property.  However, if while you are in-place editing an assembly type component, then also have another component within that one in edit mode, then an additional property would have to be used to get a reference to that one.

ThisApplication.ActiveEditDocument

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 18 of 34

WCrihfield
Mentor
Mentor

Also, it has been quite a while since I attempted to access the model browser tree of another document, other than the currently active document, by code, but right now I'm thinking that may not be possible.  I think you can only access the model browser tree of the document that is currently showing on your screen at that time...at least for some types of edit/change/write type actions.  It may be possible if just doing 'ReadOnly' stuff though.  We may need to test this theory again.  I tend to avoid navigating the model browser tree, whenever possible, so I do not do it that often, and those attempts are usually always focused on the active document (not some other document that may not even be visibly open), so I am a little rusty in that area.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 19 of 34

tom89Y38
Enthusiast
Enthusiast

I also don't like to use this method, feels tricky and unpredictable...

But I guess it's the only way since the weld suppression property is not accessible from the API ☹️

 

This is what I have right now, it opens the correct weld assembly with edit in place

	WeldSuppression(GetWeldAssy(ThisApplication.ActiveDocument, "test2"), "MijnLas", True)

 

Public Sub WeldSuppression(ByVal oWeldOcc As ComponentOccurrence, ByVal sWeldName As String, ByVal bSuppressed As Boolean)
	' Set a reference to the Assembly Document
	'Dim oWeldAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument

	oWeldOcc.Edit

	Dim oWeldAssyDoc As AssemblyDocument = ThisApplication.ActiveEditDocument

	' Set a reference to the Assembly Component Definition
	Dim oAsmCompDef As WeldmentComponentDefinition = oWeldAssyDoc.ComponentDefinition

	' Set a reference to the Model Browser Pane
	Dim oModelBrowserPane As BrowserPane = oWeldAssyDoc.BrowserPanes("AmBrowserArrangement")

 

Unfortunately I still get the mouse pointer to select a feature. Also when I do select the weld I want to suppress, nothing happens..

 

 

 

0 Likes
Message 20 of 34

mat_hijs
Collaborator
Collaborator

I tried to adapt the code, but I still can't get it to select the browser node:

Sub Main
	' Set a reference to the Assembly Document
	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
	
	' Set a reference to the Assembly Component Definition
	Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
	
	' Set a reference to the Component Occurrences
	Dim oOccurrences As ComponentOccurrences = oAsmCompDef.Occurrences
	
	' Set a reference to a Component Occurrence
	Dim oOcc As ComponentOccurrence = oOccurrences.Item(1)
	
	WeldSuppression(oOcc, "Fillet Weld 1", True)
End Sub

Public Sub WeldSuppression(ByVal oOcc As ComponentOccurrence, ByVal sWeldName As String, ByVal bSuppressed As Boolean)
	' Edit the Component Occurrence
	oOcc.Edit
	
	' Set a reference to the Assembly Document
	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveEditDocument
	
	' Set a reference to the Assembly Component Definition
	Dim oAsmCompDef As WeldmentComponentDefinition = oAsmDoc.ComponentDefinition
	
	' Set a reference to the Model Browser Pane
	Dim oModelBrowserPane As BrowserPane = oAsmDoc.BrowserPanes("AmBrowserArrangement")
	
	' Set a reference to the Welds Browser Node
	Dim oWeldsBrowserNode As BrowserNode
	For Each oWeldsBrowserNode In oModelBrowserPane.TopNode.BrowserNodes
		If oWeldsBrowserNode.BrowserNodeDefinition.Label = "Welds" Then
			Exit For
		End If
	Next
	
	' Set a reference to the Beads Browser Node
	Dim oBeadsBrowserNode As BrowserNode
	For Each oBeadsBrowserNode In oWeldsBrowserNode.BrowserNodes
		If oBeadsBrowserNode.BrowserNodeDefinition.Label = "Beads" Then
			Exit For
		End If
	Next
	
	' Get the Beads we want to suppress
	Dim oWeldBrowserNode As BrowserNode
	For Each oWeldBrowserNode In oBeadsBrowserNode.BrowserNodes
		If oWeldBrowserNode.BrowserNodeDefinition.Label = sWeldName Then
			' Get the Bead Faces Count
			Dim iBeadFacesCount As Integer = oAsmCompDef.Welds.WeldBeads(sWeldName).BeadFaces.Count
			Select Case True
				Case bSuppressed = True And iBeadFacesCount > 0
					' Bead needs to be suppressed
				Case bSuppressed = False And iBeadFacesCount = 0
					' Bead needs to be unsuppressed
				Case Else
					' Suppression state is already correct
					Exit Sub
			End Select
			
			' Get the Command Manager
			Dim oCommandManager As CommandManager = ThisApplication.CommandManager
			
			' Get the Control Definitions
			Dim oControlDefinitions As ControlDefinitions = oCommandManager.ControlDefinitions
			
			' Enable Silent Operation to avoid getting a warning message
			ThisApplication.SilentOperation = True
			
			' Select the Browser Node
			oWeldBrowserNode.DoSelect
			'ThisApplication.CommandManager.DoSelect(oWeldBrowserNode)
			'oAsmDoc.SelectSet.Select(oWeldBrowserNode)
			
			' Run the "Suppress" command
			oControlDefinitions("AssemblySuppressFeatureCtxCmd").Execute2(True)
			
			' Disable Silent Operation
			ThisApplication.SilentOperation = False
		End If
	Next
	
	' Exit the Edit the Component Occurrence
	oOcc.ExitEdit(ExitTypeEnum.kExitToParent)
End Sub

0 Likes