"If Condition" string

"If Condition" string

J.VandeMerckt
Advocate Advocate
303 Views
4 Replies
Message 1 of 5

"If Condition" string

J.VandeMerckt
Advocate
Advocate

Hi Everyone.

I found this code on the forum and saw something interesting I didn't fully understand.
Tried googling for it but couldn't find a good example.

This is the code:

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence

For Each oOccurrence In oAsmCompDef.Occurrences
	Dim oName As String
	If oOccurrence.Name.Contains("family name") And oOccurrence.Name.Contains("instance number") Then
		oName = oOccurrence.Name
		If condition Then
			oOccurrence.Suppress

		Else
			oOccurrence.Unsuppress
		End If

		Exit For
	End If

Next

In the code they use "If condition Then"
Could anyone explain this in a simple code?

Ty

0 Likes
Accepted solutions (2)
304 Views
4 Replies
Replies (4)
Message 2 of 5

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @J.VandeMerckt ,

That appears to be someone's pseudo code that they were using to ask a question, where 'condition' was some to be determined value

 

as it is written, this bit of code does nothing.

 

what are you attempting to do?

EESignature

Message 3 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @J.VandeMerckt.  That block of code does not seem to make much sense the way it currently is, but I think I understand the concept, so I copied the code, and reformulated it a bit, to match what I expect was the idea.

The term 'condition' can be 'defined' (set its Type and/or set a value to it) in a way that gives it a Boolean type value.  Then that 'condition' term would act like a local variable, representing that resulting Boolean value when used within the If...Then statement.  In the following code example, Line 9 is defining that 'variable' named 'condition'.   Otherwise it will not be recognized and will not have any meaning.

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence

For Each oOccurrence In oAsmCompDef.Occurrences
	Dim sName As String = oOccurrence.Name
	Dim condition = (sName.Contains("family name") And sName.Contains("instance number"))
	If condition Then
		oOccurrence.Suppress
	Else
		oOccurrence.Unsuppress
	End If
Next

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)

Message 4 of 5

J.VandeMerckt
Advocate
Advocate
Just learning tbh.
I thought the code looked at a statement above it and if the statement was without error then the condition is met and therefore the code continues.

But it was a bit far fetched as I understand it now.
0 Likes
Message 5 of 5

J.VandeMerckt
Advocate
Advocate
I like this way of working.
I'm not sure what I expected but I like this way of working.
Next time I'll try to incorporate this in my code.

Thanks for the time.
0 Likes