I query my components like this:
sub GetComponents Dim Objs As ViewDraw.IVdObjs Objs = vdApp.Query(ViewDraw.VdObjectTypeMask.VDM_COMP, ViewDraw.VdAllOrSelected.VD_ALL) Dim Component As ViewDraw.Component For i = 1 To Objs.Count Component = Objs.Item(i) Dim CompName As String CompName = Component.Refdes Dim CompLabel As ViewDraw.IVdLabel CompLabel = Component.Label Next i msgbox "ready" end sub
The Macro is written in VB.Net, but it is easy to transfer to VBS. It is a cutout of something bigger I have here.
So a few things are missing, like inizialization of the vdApp Object, and the Licensing.
Symbols on the root schematic don't have a '\' in the name so it will fail on the split.
So either do a check (if instr(objComp.GetName(0),"\") <> 0 then) before the split or you can add the root schematic so it always is an array
DesignName = vdapp.GetActiveDesign()
RootName = Vdapp.GetProjectData().getiCDBDesignRootBlock(DesignName)
CompfullparthWithRoot = RootName & "\" & objComp.GetName(0)
tempsplittkk = Split(CompfullparthWithRoot, "\")
If you want to get the components from your design you should use VdApp.DesignComponents(..)
vdApp.Query will only load the objects from the open pages.
So for vdapp.Query to be correct you would need to add code to open all the sheets in the board and to close all other sheets (Sheet from non instance blocks, sheets from other boards in the project or blocks from other projects (File → Open → Block...) )
Start by just using comp.GetName(0). It will return a string. See what that string is, then decide what to do with it. Split, parse, or whatever it is you are trying to get from the name.
GetName returns the Id of the component. You can see what that looks like by selecting any component and viewing its properties. The property name is Id. Unless it's an off-page connector, or some other component that has a property called Name. Then it returns the value of the Name property.
Thanks for your updates. We were partly successful but now the issue seems to have got a lot more complicated.
We are reading all the design components in one function and filtering out annotate type components and storing the resulting objects in an array or dictionary in VB .NET.
This array or dictionary is being called later on in the code at which point the objects are not remaining and code is throwing the (Exception - Unable To Allocate Object Collection)
Is there anything that has to be done to retain the objects? The weird thing is that the objects are lost only during every second run of the code. During the first run, they are available across different functions.
1 of 1 people found this helpful
This is most likely a syntactical problem of some kind related to your use of the dictionary and/or the collection of the design components. If you add the relevant sections of code as an attachment here, we may be able to help get it sorted out.
Common problems I've encountered with dictionaries and other collections:
- trying to modify or remove an element while looping through the collection, when the collection itself is used as the loop reference
- not clearing the collection before recreating it, resulting in duplicate elements
- Not initializing the collection before using it. For example you have to use the New statement with a dictionary unless you derive it as a value of some other variable.
Those are the kind of things I'd be looking for in your code.