How to move an Occurrence programatically without rename?

Valued Contributor
Valued Contributor

Hi All.

I've got a problem with moving (in my case "move" means "copy to...") Occurrences without renaming them.

 

Every time, when I'm executing the following Code:

 

File.Copy(_oldPath, nPath);

_occ.Replace(nPath, true); //npath = where to move, same FileName; _occ = SolidEdgeAssembly.Occurrence

 

it changes nothing. No error, no warn. Nothing.

 

When I'm trying to replace this occurence with copied one manually, I'm getting an error, which is saying more or less:

"You're not allowed to replace this occurrence with the same occurrence from another folder".

 

Is there any other way to do this properly with Solid Edge API?

 

Regards from Poland,

Piotr

 

 

 

5 REPLIES

Re: How to move an Occurrence programatically without rename?

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Hi,

It seems to be  the expected behavior.

 

When replacing a file that is in the same directory that the assembly, you cannot replace it by a file with the same name.

 

It works exactly the same way when you do it in Solid Edge.

 

Try to change the name of the copy and then replace.

 

Regards,

 

Romuald


Romuald BERTIN

Re: How to move an Occurrence programatically without rename?

Valued Contributor
Valued Contributor

@rbertin - thank you for your reply.

 

It seems to work as expected, but it is not.

Steps to reproduce:

Hint: replacement file has the same name as replaced, but physicaly is stored in other folder!

1. copy file to any other location, without changig FileName

2. replace occurrence with the copied file (both files have the same Name)

 

All I want to do is to "organize" the structure of parts in SE-Assembly programatically.

Re: How to move an Occurrence programatically without rename?

Legend
Legend

I think you have to Move instead of Copy.

 

If you try to replace a part by another one with the same name, Solid Edge asks you for use the part that is currently loaded in the assembly.

 

It only allows you to replace a part by a file with the same name if the link to that part is broken and you are "redefining" it.

 

You can use the command "save as.." with the same name to a new location and Solid Edge will create the new file and "point" to that new file.

 

 

Héctor Pelayo Izquierdo
Engineering Department, JAE Ingeniería y Desarrollos, S.L.
Solid Edge ST9 MP5 | NX 9
Development: VB.NET

Re: How to move an Occurrence programatically without rename?

Valued Contributor
Valued Contributor

@Hector - thank you for your hints!

 

Finally - it works perfectly with RevisionManager.

Re: How to move an Occurrence programatically without rename?

Phenom
Phenom
Solid Edge will always look for parts in the same folder as the assembly. So if your part and assembly had been in different folders the copy/replace would have worked - as it does interactively and in Rev Manager.
That is why you can move/copy an assembly and its parts with windows explorer provided all the files are all in the same folder (or folder structure).
However, that would break any links to files outside of that folder, so files should never be moved that way.
HP Z420 16GB RAM
Quadro K4000
ST7 MP10 on Windows 7 Pro 64.