Identify Weld Occurrence

Identify Weld Occurrence

cencinaNB2ET
Advocate Advocate
1,403 Views
5 Replies
Message 1 of 6

Identify Weld Occurrence

cencinaNB2ET
Advocate
Advocate

HI,

 

I been identifying files inside an assembly to get certain properties and data.

The problem i Have is that a Weldment Assembly identifies a Weld as an occurrence, with no filename

I need my browser to be driven by filenames so this returns an error for me.

 

I want to skip the Weld Occurrences but i cant find anything of the forum or other blogs how to identify a weld.

 

This is what i have so far:

 

SyntaxEditor Code Snippet

Dim oDoc As AssemblyDocument 
oDoc = ThisDoc.Document
Dim Occurrences As ComponentOccurrences 
Dim oOcc_A As ComponentOccurrence

Dim oCompDef As AssemblyComponentDefinition 
oCompDef = oDoc.ComponentDefinition 



For Each oOcc_A In oCompDef.Occurrences


If  Not TypeOf oOcc_A.Definition Is kWeldsComponentDefinitionObject Then
MessageBox.Show(oOcc_A.Name, "")
End If



Next
0 Likes
1,404 Views
5 Replies
Replies (5)
Message 2 of 6

MechMachineMan
Advisor
Advisor

Have you tested the code you wrote?

 

Looks like it should work just fine.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 6

cencinaNB2ET
Advocate
Advocate

Yes, I tested it...

it didn't work

 

but I worked out that the name of the Weld take on the assembly name if the browser is set to the filename

And blank otherwise...

So I just have two conditions taking care fo this in either case.

 

but it would be good to use a less rudimentary method...

 

 

0 Likes
Message 4 of 6

DRoam
Mentor
Mentor

For anyone else trying to do this, the code the OP was trying to use was this:

 

If TypeOf componentOccurrence.Definition Is kWeldsComponentDefinitionObject Then
	[...]
End If

The reason this was not working is it's trying to compare a data type ("TypeOf componentOccurrence.Definition") against an Inventor ObjectTypeEnum enumerator value ("kWeldsComponentDefinitionObject").

 

To find out if an occurrence is the Welds occurrence, you have to either do a data type check OR an ObjectTypeEnum enumerator check, like so:

 

Using data type check:

If TypeOf componentOccurrence.Definition Is WeldsComponentDefinition Then
	[...]
End If

 

Using ObjectTypeEnum enumerator check (recommended):

If componentOccurrence.Definition.Type = ObjectTypeEnum.kWeldsComponentDefinitionObject Then
	[...]
End If

 

Either one is valid. I usually like to use the data type check, because it's "safer" -- if you try to do the enumerator check on a non-Inventor object, you'll get an error, because it won't have the ".Type" property. However, if you know you're dealing with an Inventor object, the enumerator check will be faster.

 

And in this case, componentOccurrence.Definition will always return a ComponentDefinition Inventor object, which will always have a Type property. So in this case, I would recommend using the enumerator check.

Message 5 of 6

Maxim-CADman77
Advisor
Advisor

"... the enumerator check will be faster".

@DRoam ,
I wonder do you know what is a duration difference (in%)?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Hi @Maxim-CADman77.  One of the common ways to check the time it takes for code tasks to complete is the System.Diagnostics.StopWatch Class object.  Below are two very basic iLogic rules which you can use to test very similar tasks as what was mentioned there.  Both rules get a reference to the local/active document, then both rules only check if the document is an assembly, in two different ways.  In this case, the Enum check seems to be taking a longer time the to process than the 'data type' check (using TypeOf).  Results vary, but the data type check seems to be somewhere in the range of 4.5 to 4.6 x (450% - 460%) faster than the Enum check.

Enum check rule:

Sub Main
	Dim oDoc As Document = ThisDoc.Document
	Dim oADoc As AssemblyDocument = Nothing
	Dim oTimer As New Stopwatch
	oTimer.Start
	If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		oADoc = oDoc
	End If
	oTimer.Stop
	Logger.Info("Enum Check Time = " & oTimer.ElapsedTicks.ToString)
	oTimer.Reset
End Sub

TypeOf check:

Sub Main
	Dim oDoc As Document = ThisDoc.Document
	Dim oADoc As AssemblyDocument = Nothing
	Dim oTimer As New Stopwatch
	oTimer.Start
	If TypeOf oDoc Is AssemblyDocument Then
		oADoc = oDoc
	End If
	oTimer.Stop
	Logger.Info("Data Type Check Time = " & oTimer.ElapsedTicks.ToString)
	oTimer.Reset
End Sub

My iLogic Logger window is showing showing results similar to the following:

INFO| 12: >>---------------------------
INFO|Enum Check Time = 190
INFO| 13: >>---------------------------
INFO|Data Type Check Time = 42

Wesley Crihfield

EESignature

(Not an Autodesk Employee)