Suppressing welds

Suppressing welds

dbushDQ3RE
Participant Participant
2,959 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,960 Views
33 Replies
Replies (33)
Message 21 of 34

mat_hijs
Collaborator
Collaborator

Weirdly enought it does seem to find the browsernode correctly, it just doesn't select it.

Message 22 of 34

WCrihfield
Mentor
Mentor

You may just need to insert some MsgBox(), MessageBox.Show(), or Logger.Debug() type lines of code in there in a bunch of places, as a form of feedback, at least temporarily, and check to make sure variables are getting values assigned to them, what values they are getting, or whatever makes sense in that location of the code.  Maybe add a few Try...Catch...End Try statements in there in places where it may throw an error, with an information message on the Catch side.  Not sure.  Just throwing general ideas out there, along the lines of what I might do in situations like that.  Once you figure out what is going on, of get it working, the messages or Logger lines can be removed, or commended out again.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 23 of 34

mat_hijs
Collaborator
Collaborator

I did that, that's how I know that it does seem to find the browsernodes, but won't select them.

0 Likes
Message 24 of 34

WCrihfield
Mentor
Mentor

If you are able to obtain the BrowserNode in the other document, but just can not select it, that would confirm my earlier suspicion about us having 'ReadOnly' access in those areas, but not 'Read/Write' access to them.  But more testing may be needed to be absolutely sure.

Just out of curiosity, is there more than just the one, original ModelState in that weldment assembly?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 25 of 34

tom89Y38
Enthusiast
Enthusiast

In my test environment there is only one Model State (the Primary one)

0 Likes
Message 26 of 34

tom89Y38
Enthusiast
Enthusiast

Hi guy's,


When I check the selected status it's False

tom89Y38_0-1715930838069.pngtom89Y38_1-1715930844075.png

			' Select the 
			oWeldBrowserNode.DoSelect
			Logger.Debug(oWeldBrowserNode.selected)

 

Could it be that we need to expand the weld and beads section first?

tom89Y38_2-1715931021218.png

 

 

0 Likes
Message 27 of 34

tom89Y38
Enthusiast
Enthusiast

I found a workaround.

It opens the weld assembly instead of edit.

 

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

	'oWeldOcc.Edit
	'open  weld assembly
	Dim oFullDocNameAAssyDoc As AssemblyDocument = TryCast(oWeldOcc.Definition.Document, AssemblyDocument)
	Dim oFullDocName As String = oFullDocNameAAssyDoc.FullDocumentName
	Logger.Debug(oFullDocName)
	DocOpen = ThisApplication.Documents.Open(oFullDocName,True)
	
	'Dim oWeldAssyDoc As AssemblyDocument = ThisApplication.ActiveEditDocument
	Dim oWeldAssyDoc As AssemblyDocument = oFullDocNameAAssyDoc

	' 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

			' 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 weld
			oWeldBrowserNode.DoSelect
			
			' Run the "Suppress" command
			oControlDefinitions("AssemblySuppressFeatureCtxCmd").Execute2(True)

			' Disable Silent Operation
			ThisApplication.SilentOperation = False
			End If
	Next
	
	'open previous active document
	oCurrentActiveDoc.Activate
End Sub

 

 

0 Likes
Message 28 of 34

WCrihfield
Mentor
Mentor

OK @tom89Y38.  Good to year you got something working for you.  Since it looked a little long, and may have been missing a check in there for whether or not the suppression command should actually run or not (depending on what is being asked for, and what the model status is), I copied the code over into a local iLogic rule editor window to edit it a bit.  Attached is a text file containing a condensed version of your code, with a few more checks included along the way, to make it slightly more robust, including a possible feedback message or two, just in case a weld bead with that name was not found.

 

I also changed the 'SilentOperation' setting to the 'iLogic Only' version.  There are 3 versions of that control...one that effects the whole application, one that effects everything done through iLogic, and one that will only effect this one iLogic rule.  The setting that would only effect this one rule is actually in the 'Options' tab of the iLogic Rule editor dialog, while you are editing this rule.  That setting can also be accessed by code, but was meant for controlling 'other' rules, not the rule that the code is already within (can't control itself, from within itself).  Since this type of setting can be critical, if not handled properly, I prefer to use the version with the least scope (area of effect).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 29 of 34

tom89Y38
Enthusiast
Enthusiast

Hi @WCrihfield, thanks for the reply.

Today I'm not able to test it anymore. but can I ask you one more thing?

Instead of suppressing/unsuppressing 1 weld, I want to be able to loop through an dictionary.

I started already like this:

	WeldSuppression(GetWeldAssy(ThisApplication.ActiveDocument, "test2"), New Dictionary(Of String, Boolean) From {{"MijnLas", True }, {"MijnLas2", True }, {"MijnLas3", True }})

 

the Sub program starts like this:

Public Sub WeldSuppression(ByVal oWeldOcc As ComponentOccurrence, ByVal oWeldDictionary As Dictionary(Of String, Boolean))

 

 

Why I do this? I want to reuse this kind of suppressing methods for welds in a lot of iLogic generated models.

If we by default add the function and sub program to our code, then our team members only need to add 1 rule where they can specify the correct weld assembly and the weld with their suppression state.

 

I didn't have a lot of time today to adjust the For loop, but I don't see the loop anymore in your code. Is it possible to adjust your code with the dictionary? I'm scheduled some time to test it beginning of next week

 

0 Likes
Message 30 of 34

WCrihfield
Mentor
Mentor

Hi @tom89Y38.  That certainly sounds possible, and a good idea for efficiency/performance.  I do have multiple projects going on right now, but I may be able to schedule working on that modification into my day.

 

I just wish there was a good way to select multiple specific BrowserNodes (without selecting them all), then execute that command on them all just once.  That would make it even more efficient and faster.  Unfortunately, the DoSelect method will unselect whatever was selected before, to select the new object, so only one thing can be selected that way at a time.  Using SelectSet seems to be out of the question right now, and it seems like we can not add BrowserNode objects to an ObjectCollection, so that route will not work either.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 31 of 34

WCrihfield
Mentor
Mentor

Hi @tom89Y38.  Here is something you can try out.  Keep in mind that I have not tested this yet myself.  Attached is a text file containing all the code of all 3 routines that I have modified a bit.  It includes the Dictionary idea, but just does not set all its variations within a single line where it calls that routine to run.  That would be a really long line of code, and I find that it is usually best to break stuff down a bit.  Instead, it sets the variations within the 'Main' routine, then supplies that Dictionary object to the routine.  I tried to be fairly thorough (avoid potential errors), but it may be wise to also enclose the Dictionary loop within a Try...Catch...End Try statement, just to make sure that if an error does happen in that area, your code will still make it to the line of code where it turns the 'SilentOperation' back off.  But since it is just iLogic scoped, it is not as critical.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 32 of 34

tom89Y38
Enthusiast
Enthusiast

Hi @WCrihfield ,

 

 

I didnt try your code yet, (it's a bit to hard to understand and debug for me). So I continued using mine.

Unfortunately, while debugging, I'm facing an issue that I can't solve. And I think there will be no solution for it 😞

 

Sometimes I need to suppress welds that have an error (see picture). Off course the face count of these welds is zero.

tom89Y38_0-1717591166784.png

So this Case statement does not work correctly anymore:

tom89Y38_1-1717591219991.png

 

I don't see any other usable options in the API.

Do you have some other options?

 

0 Likes
Message 33 of 34

WCrihfield
Mentor
Mentor

Nope.  As far as I know, we do not even have a good way of checking that 'in error' status.  Some object types in Inventor's API give us a ReadOnly property like 'HealthStatus', which will have a variation of the HealthStatusEnum as its value, and we can use that to check stuff like this.  Nothing here like that, as far as I can tell.

But, I would suggest/recommend changing that awkward looking Select Case statement over into a regular If...ElseIf...Else...End If statement.  "Select Case True" is meaningless, and not logical to look at.  Select Case statements can be beneficial in situations where a long list of variations are being tested, or when groups of possible values can/need to be handled in different ways per group.  Just a friendly suggestion.

If suppress = True And iBeadFacesCount > 0 Then
	'bead needs to be suppressed
ElseIf suppress = False And iBeadFacesCount = 0 Then
	'bead needs to be unsuppressed
Else
	'suppression state is already correct
	Continue For
End If

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 34 of 34

tom89Y38
Enthusiast
Enthusiast

Thanks for the quick reply and suggestion, Unfortunately, suppressing welds with iLogic comes to a dead end for me.

If I can't check the health status the whole code is useless 😞

 

Hopefully Autodesk extends the API with more functionality for welds and weld assemblies.

 

Thanks anyway!!

0 Likes