1 of 1 people found this helpful
I think you need to play with all the possible VdOrientation constants and see how they work. Their behavior is kind of odd, so the results may not be what you expect. I'm not clear on why it's even necessary to mess with the pins and their locations - they should be the same on the new part so I'm not seeing how it matters.
By the way, I've found it easier to delete the old part and place a new one using something like:
comp = sheetblock.AddPartInstance(newpartition, newpn, newsymbolname, loc.X, loc.Y)
then add the needed properties from DxDatabook by going directly to the database for that part and using the comp.AddAttribute function. I've never had very good results using the replace function, or using the built-in Replace Symbol function in DxDesigner. Properties have gotten mixed up and other similar issues like the ones you are dealing with.
thanks for the reply.
I've tried all possible variations of orientation, but none works as I would expect. The main issue with my symbol is that the origins of original and replacement symbol are not the same. So when I replace the symbol it's always a little shifted from original. That's why I wanted to use pin location. If I can force the position of component in reference to pin location, that'd be fantastic. But that didn't work either. Is there any approach that could do something like that? How can I walkaround the difference of origin?
The approach you're suggesting doesn't solve my problem either. Even though I rotate the symbol (original is vertical by default, replacement is horizontal by default), it's still shifted due to difference in origin. Furthermore, your approach just places the block, without any pin numbers, nets or anything. I am fairly new to automation and I am still not fully aware what's the difference between blocks and components and how can a block become a component.
If your component origins are not the same it makes sense that it will not be in the same place.So here's what I'd do in this case:
1. Before replacement, get the compent origin (comp.getlocation) as ivdpoint. Let's call it orig_loc.
2. Get connections as you have done and get the location of pin 1. pin1_loc
3. Subtract pin1_loc from orig_loc. orig_diff
4. Place the new component at orig_loc.
5. Get new pin1 loc. new1_loc
6. Subtract new1_loc from orig_loc. new_diff.
7. Subtract new_diff from orig_diff, and move the component by that amount. It will now be in the correct location such that pins (if they are all in relatively same locations as the original part) will all be in the right places.
The ivdpoint objects don't support vector manipulation as I described, so you will have to break this down to the x and y components of the various locations, but the logic is the same. Just do the same with the x and y individually and you'll get the same result.
I've came to similar conclusion. A little bit of math and it works. And connections (nets) are automatically assigned, so I don't need to worry about that either.
But I have another problem I need to solve. The script deletes all symbols, but adds only the last component it traverses. It's very strange behaviour and perhaps you have some idea why it would do that.
I'm going through all components:
For Each Comp in ActiveView.Query(VDM_COMP, VD_ALL)
Checking the symbol name:
symbol = nkBlock.GetName(SHORT_NAME) & "." & nkBlock.SheetNum
Triggering when I find a symbol that needs replacing:
Select Case symbol
Then I get all info I require (like pin position, component position). When I got the info I delete old symbol, add new one, rotate, set ref des and part number:
set sheetcomp = sheetblock.AddPartInstance("", "", "CAP", X1 + DeltaX, Y1 + DeltaY)
sheetcomp.orientation = VDORIENT_ROT270
sheetcomp.Refdes = RefDes
Set sheetblockPN = sheetcomp.addattribute("Part Number=" & PN, X , Y, 0)
I don't know why the part number is visible, even though I set flag as 0 (VDINVISIBLE), but that's a minor thing.
I appreciate all your help. Thanks to you I'm on the right track.
1 of 1 people found this helpful
comp.Selected = True
Check the Advanced settings in the Property Definition Editor for your part number property. It's visibility might be set to yes.
You're welcome. Glad it's working out.
Patrick, have you ever had any issues with AddPartInstance? Since I added it to the script, my instance of DxDesigner started crashing. As soon as I remove it, the script goes all the way through.
1 of 1 people found this helpful
Yes. Make sure you are actually getting the text strings you want for each part of the addpartinstance function call. It is most likely that you think you are supplying an argument with a value you got somewhere else, but you are actually supplying an empty string. If all the parameters are not there (and correct) it will crash.
I wasn't supplying Device information at all. This is something that we don't use in Expedition environment, that's why I got confused. Luckily we will do these kind of transformation only on old designs made in PADS, where device attribute is present.
Obviously you've done similar transformations on your own designs. Do you have any suggestion on improving the speed of the process? Currently it takes more than 10 minutes to go through entire project (~500 components). I tried storing only relevant component unique id in a dictionary and than process only those, but that didn't have any impact on the speed whatsoever.
I have used this function to enable component replacement during schematic capture. The engineers often have cases where they want to make refinements such as value changes to resistors and capacitors. The Replace Part function in DxDesigner is lacking (IMO), so I made my own that is much easier to use. For example you don't need to go find the new symbol name; just select a part in DxDatabook. All the pertinent information is captured from Databook. The old part is deleted, the new part is added, then all the correct properties are added from DxDatabook as if the part had been placed normally.
I made a video of it here.
As for the speed, I don't have any great ideas. We are interacting with the software via COM transactions, which are inherently slower. For me the point is that this method is still many times faster than doing it manually, so I put up with it. But a few tips I can tell you:
- Accessing a database (eg the MS Access database we use for DxDatabook) is much faster than accessing the Central Library by way of Automation.
- There is a lot less overhead dealing with arraylists and dictionaries than with arrays.
- If you can avoid opening a schematic sheet, do it. For example use the app.DesignComponents function to get a reference to all the parts in a design instead of iterating through the sheets and trying to select them from the sheet.
I like your last suggestion, but I don't imagine how can you place the component on the correct sheet if you don't traverse them? I have a reference to component and the parent sheet number (sheet number), but SetLocation method specifies only X and Y location.
The issue I'm experiencing is that I place all components only on the first sheet. Other sheets remain unchanged.
I have done something similar and it creates the part with no issue. However, it will not remove the part I'm trying to replace.
if (direction == "RIGHT")
port.LegacyComponent.Selected = true;
_dx.Application.ActiveView.Block.AddComponent(port.Name + "_R.1", port.Xcoord, port.Ycoord);