Assign component occurrence to variable

Assign component occurrence to variable

Anonymous
Not applicable
700 Views
2 Replies
Message 1 of 3

Assign component occurrence to variable

Anonymous
Not applicable

 

Hi,

 

I'm trying with vb.net to assign a virtual component to a variable. The following code creates the virtual component "Assembly" if it doesn't exists :

 

Dim _asmCompDef As AssemblyComponentDefinition
_asmCompDef = _doc.ComponentDefinition

 

Dim identity As Matrix
identity = _invApp.TransientGeometry.CreateMatrix

 

Dim occs As ComponentOccurrence
occs = _asmCompDef.Occurrences.AddVirtual("Assembly", identity)

 

I don't know how to assign this virtual component to a variable.

This code creates an error :

 

Dim existingOcc As ComponentOccurrence
existingOcc = _asmCompDef.Occurrences.Item("Assembly")

 

 

 

 

 

 

0 Likes
Accepted solutions (1)
701 Views
2 Replies
Replies (2)
Message 2 of 3

adam.nagy
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

The best thing is always to test things in VBA. There you would have got a Type mismatch error that could have pointed you in the right direction.

Item() expects a Long input parameter. You could use ItemByName instead, but that as well will also need the occurrence counter too, i.e. "Assembly:1"

 

I hope this helps,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 3 of 3

Anonymous
Not applicable

Your advice has helped. Thanks alot.

0 Likes