API import iges

API import iges

Anonymous
Not applicable
759 Views
4 Replies
Message 1 of 5

API import iges

Anonymous
Not applicable

Cannot save the file because of error.

 

Dim oIges As String
oIges = "C:\Test\Drawing1.iges"
  
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim oICDef As ImportedGenericComponentDefinition
oICDef = oCompDef.ReferenceComponents.ImportedComponents.CreateDefinition(oIges)
oICDef.ImportedAssemblyOrganizationType = kImportedAsCompositeFeaturePart

oCompDef.ReferenceComponents.ImportedComponents.Add(oICDef)iges error.JPG
0 Likes
760 Views
4 Replies
Replies (4)
Message 2 of 5

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

I tried your code and it works the first time I run it in a part.

Then it doesn't work. I got the same error message as you.

I then unchecked "Silent operation" for the rule which gave this message:

IGES.PNG

The part file has been renamed to the same name as the iges-file. Thats why it doesn't work.

You could try just changing the name of the FullFileName of the part file. Then the code runs without errors again.

Dim oIges As String
oIges = "C:\Users\hfljf\Desktop\Drawing1.iges"
  
Dim oDoc As PartDocument

oDoc = ThisApplication.ActiveDocument
'---------Something like this---------------------------
oDoc.FullFileName = oDoc.FullFileName & "SomeRandomText"
'-------------------------------------------------------
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim oICDef As ImportedGenericComponentDefinition
oICDef = oCompDef.ReferenceComponents.ImportedComponents.CreateDefinition(oIges)
oICDef.ImportedAssemblyOrganizationType = kImportedAsCompositeFeaturePart

oCompDef.ReferenceComponents.ImportedComponents.Add(oICDef)

EDIT: also change the file path back tou your original path 🙂

0 Likes
Message 3 of 5

JhoelForshav
Mentor
Mentor

Sorry! @Anonymous 

Ignore my last answer. I must have been very tired this morning when I wrote it. You can only change the fullfilename like that if the part has never been saved before. And, it would make no sense to save it to something that doesn't even have a file extension.

 

I feel dumb now...

 

Anyways, the problem with the "document with same path" is still real. I'll investigate further what actually happens and see if I can find a solution 🙂

0 Likes
Message 4 of 5

Anonymous
Not applicable

No worries @JhoelForshav  and thank you for your time. I didnt expect that it changed the filename. It is supposed to add only the geometry. Im looking an alternative which batch convert those iges to ipt, then derive them.

0 Likes
Message 5 of 5

Anonymous
Not applicable

Another option is to use Inventor's task scheduler to import the files?

An out of the box tasks is "Import Files"

@ClintBrown3D Autodesk Inventor 195.png