Knowing the UID(or X, Y location) of a component, is there any function which can return the Component object? We have a list of UID and want to change the according components' RefDes by scripting.
Sub modify_comp(UID as String)
comps = doc.Components
For Each comp In comps
if comp.UniqueId = UID then
'modify the comp
Keep in mind that it may be much faster to make your own collection of components in a dictionary, list, or arraylist prior to doing this kind of operation. That way you can get the reference to the component of interest much faster than having to iterate through all of them every time. For example make a dictionary with uniqueId as the key and the component as the value. It would do the full iteration once to load the dictionary then getting each specific component would be abuot 1000X faster.
Thank you Patrick. I also thought it'll be slow if I compare all of them each time so I tried to find a way which can return the component directly. Your suggestion of minimizing the collection seems to be a good way.
Now I'm using
colComponents = Application.DesignComponents("", Application.GetProjectData.GetiCDBDesignRootBlock(Application.ActiveView.GetTopLevelDesignName()) , "-1", "STD", True)
which includes all sheets. The third argument "Endsheet" seems can only define pagenumber of the last sheet. Can I get components in a particular sheet, like sheet 15 efficiently?
I was not aware you are doing this in DxDesigner. You are on the right track, though. Use that function to get all the design components, cycle through them, and add to a dictionary as I mentioned above. Then you can use the UID to get any comp from the dictionary and it will be very fast. Once you have the comp reference you can get anything about it.
Thanks a lot!
Retrieving data ...