Cancel
Showing results for 
Search instead for 
Did you mean: 

Replacing Solid Edge Assembly References using API

Pioneer
Pioneer

Hi All, I'm coming from SolidWorks background, and need help in Solid Edge API for replacing assembly references.

 

I tried folowing method, but it is not working :

oapp.ReplaceReference(oldnamewithext, oldnamewoext + "_" + newdir + "." + ext, outpath + "\" + newdir, False)

Need your help. Thanks.

2 REPLIES 2

Re: Replacing Solid Edge Assembly References using API

Pioneer
Pioneer

Thanks Tushar Suradkar for suggesting oasm.replacecomponents method. Here is my code which works :

 

oapp = Marshal.GetActiveObject("SolidEdge.Application")
odoc = oapp.Documents.Open("C:\sabc123\coupling_sabc123.asm")
oasm = odoc
For i = 1 To oasm.Occurrences.Count
Dim ooccu As SolidEdgeAssembly.Occurrence = oasm.Occurrences.Item(i)
Dim sa As System.Array = {ooccu}
oldnamewithextinst = ooccu.Name.Substring(ooccu.Name.ToString.LastIndexOf("\") + 1)
oldnamewithext = oldnamewithextinst.Substring(0, oldnamewithextinst.LastIndexOf(":"))
oldnamewoext = oldnamewithext.Substring(0, oldnamewithext.LastIndexOf("."))
ext = oldnamewithext.ToString.Substring(oldnamewithext.ToString.LastIndexOf(".") + 1)
newname = txtOutPath.Text + "\" + txtNewDirName.Text + "\" + oldnamewoext + "_" + txtNewDirName.Text + "." + ext
oasm.ReplaceComponents(sa, newname, ConstraintReplacementConstants.seConstraintReplacementNone)
Next

Re: Replacing Solid Edge Assembly References using API

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

Glad to know 'ReplaceComponents' worked.

   

Also, I'd like to suggest the following direct functions in DotNet to replace extensions:

System.IO.Path.GetFileNameWithoutExtension
System.IO.Path.ChangeExtension

   

Hope you find them useful.

   

Regards,

Tushar