C++ Get the file path for components which come from other CADs

C++ Get the file path for components which come from other CADs

pierluigi.gulmini
Participant Participant
437 Views
4 Replies
Message 1 of 5

C++ Get the file path for components which come from other CADs

pierluigi.gulmini
Participant
Participant

Hi all.

I created an Inventor 2021 assy (attacched as .zip) which is made up by 4 files: two are standard Inventor .ipt ones, while the others come from Solid Edge and SolidWorks files references too.

To made the assy up I used the 'Place Imported CAD Files' command.


Here is the assy structure:

Top node: invA004-CAD-00000108.iam

1st child → invP001:1 (invP001-CAD-00000102.ipt) →INVENTOR

2nd child → seP001-CAD-00000101:1 (seP001-CAD-00000101.par) → SOLID EDGE

3rd child → swP014-CAD-00000100:1 (swP014-CAD-00000100.SLDPRT) → SOLIDWORKS

4th child → invP002-CAD-00000104:1 (invP002-CAD-00000104.ipt) →INVENTOR

5th child → invP002-CAD-00000104:2 (invP002-CAD-00000104.ipt) →INVENTOR

 

Analyzing the assy I noted that when I try to get the occurences full paths thru the code below:

 

CComQIPtr<ComponentOccurrence> pCompOccurence = GetOccurence(); // to get the child occurrence
CComPtr<ComponentDefinition> pCompDef;
pCompDef = pCompOccurence->Definition;
CComPtr<IDispatch> pDispDoc = pCompDef->Document;
CComPtr<Document> pDoc;
if (pDispDoc)
{
pDispDoc.QueryInterface(&pDoc);
_bstr_t fullFileName = pDoc->FullFileName;
USES_CONVERSION;
std::string componentFullFilePath = OLE2A(fullFileName);
}


the resulting 'componentFullFilePath' string is a standard file path for Inventor .ipt components, while "codified" in case of other CADs ones.

For example, considering all files are in the 'C:\myPws' directory, in case of invP001:1 node I correctly obtain the 'C:\myPws\invP001-CAD-00000102.ipt' value, while for the seP001-CAD-00000101:1 node the '**C:\myPws\invA004-CAD-00000108.iam*LocalDocs*xAaaaqfdaAaaaaaaaAaaaaqcfWa*seP001-CAD-00000101.ipt' value.


However, I noted that for both Solid Edge and SolidWorks files, Inventor API return a good file path value when interrogating for OLE file descriptors, that is 'C:\myPWS\seP001-CAD-00000101.par' and 'C:\myPWS\swP014-CAD-00000100.SLDPRT'.

 

CComPtr<Document> m_InvenDoc = GetDocument(); // to get the current assy object
CComPtr<ReferencedOLEFileDescriptors> pRefOLEFileDescs;
pRefOLEFileDescs = m_InvenDoc->GetReferencedOLEFileDescriptors();
long OLERefCount = pRefOLEFileDescs->Count;
EPStatusType st = OK;
for (long i = 1; i <= OLERefCount; i++)
{
CComPtr<ReferencedOLEFileDescriptor> pRefOleFileDesc;
pRefOleFileDesc = pRefOLEFileDescs->GetItem(i);
_bstr_t fullName = pRefOleFileDesc->FullFileName;
USES_CONVERSION;
std::string fileName = OLE2A(fullName);
}


So... the question is: is there a way for getting good imported CAD files file paths while handling occurrences objects?

Thanks

0 Likes
Accepted solutions (1)
438 Views
4 Replies
Replies (4)
Message 2 of 5

basautomationservices
Advocate
Advocate

I quickly tried this in VBA, for me the occurrence method returns the FullFilename just fine with an SE part. It was converted to an .ipt when importing though. How did you get it to stay a .par / .sldprt after inserting the imported component?

 

How are you running this code? Are you using apprentice?

 

What is the value of fullFileName here? 

_bstr_t fullFileName = pDoc->FullFileName;

 

Contact me for custom app development info@basautomationservices.com. Follow below links to view my Inventor appstore apps.

Free apps: Smart Leader | Part Visibility Utility | Mate Origins

Paid apps: Frame Stiffener Tool | Constrain Plane Toggle | Property Editor Pro


0 Likes
Message 3 of 5

pierluigi.gulmini
Participant
Participant

Firstly, thanks for your reply and test.

 

When using the 'Place Imported CAD Files' for adding Solid Edge, SolidWorks, Creo, etc files into an Inventor assembly, after the file selection step, Inventor asks if you want to add/import "foreign files" as Referenced Models or Converted ones. I always use the 'Reference Model' import type option, for example:

 

pierluigigulmini_1-1649860904993.png

 

This choice allows you to modify the .SLDPRT file with SolidWorks and have all modifications within the Inventor assy for free.

 

My software is a simple C++ console apllication which uses Inventor COM API, not Apprentice.

 

Debugging values:

pierluigigulmini_2-1649861599423.png

0 Likes
Message 4 of 5

basautomationservices
Advocate
Advocate
Accepted solution

I see. That was where I was doing it differently.

 

To get the actual fullfilename you need to get the 'AssociativeForeignFilename' property from the componentoccurrence.

Contact me for custom app development info@basautomationservices.com. Follow below links to view my Inventor appstore apps.

Free apps: Smart Leader | Part Visibility Utility | Mate Origins

Paid apps: Frame Stiffener Tool | Constrain Plane Toggle | Property Editor Pro


0 Likes
Message 5 of 5

pierluigi.gulmini
Participant
Participant
Thanks 😉