Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results forĀ 
ShowĀ Ā onlyĀ  | Search instead forĀ 
Did you mean:Ā 

Automate .ipt to adsk convertion

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
Anonymous
1313 Views, 10 Replies

Automate .ipt to adsk convertion

Is there a way to automate .ipt to adsk conversion? I believe this can be done by ilogic or macro but I dont know how.

10 REPLIES 10
Message 2 of 11
lmc.engineering
in reply to: Anonymous

Hi @Anonymous

 

You can achieve this using the following:

 

SyntaxEditor Code Snippet

Dim oDoc As Document = ThisApplication.ActiveDocument
CompDef = oDoc.ComponentDefinition
FullFileName = "YourFilePath\YourFileName.adsk"
CompDef.BIMComponent.ExportBuildingComponent(FullFileName)  

 If you go to Help>Programming/API Help and search 'BIMComponent', you'll find everything you need there.

Message 3 of 11
Anonymous
in reply to: lmc.engineering

thank you @lmc.engineering. Do you know how to set the file name automatically to use the same as source name?

\YourFileName.adsk"

 

Message 4 of 11
lmc.engineering
in reply to: Anonymous

You can use any of the below for this.

 

SyntaxEditor Code Snippet

'''The below gets the file path and file name
Dim
FileSource As String = ThisDoc.PathAndFileName(False) ''' False leaves off the extension (ie .ipt)
'''The below gets just the file name Dim FileName As String = ThisDoc.FileName(False) '''False leaves off the extension
'''The below gets just the file path Dim FilePath As String = ThisDoc.Path 

 

Message 5 of 11
Anonymous
in reply to: lmc.engineering

It is not getting the file name, it write the code exactly as file name.

Message 6 of 11
lmc.engineering
in reply to: Anonymous

Can you post what code you have and I'll take a look.

Message 7 of 11
Anonymous
in reply to: lmc.engineering

SyntaxEditor Code Snippet

Dim oDoc As Document = ThisApplication.ActiveDocument
CompDef = oDoc.ComponentDefinition
FullFileName = "ThisDoc.FileName(False) 'without extension.adsk"
CompDef.BIMComponent.ExportBuildingComponent(FullFileName) 
Message 8 of 11
lmc.engineering
in reply to: Anonymous

Ok, so I can see where the confusion has come from. It was probably a bit misleading with the parameter 'FullFileName'. What we actually need is the file path and file name, as below

 

SyntaxEditor Code Snippet
Dim oDoc As Document = ThisApplication.ActiveDocument
CompDef = oDoc.ComponentDefinition
FullFilePathandName = ThisDoc.PathAndFileName(False)
FileFileName = FullFilePathandName & ".adsk"
CompDef.BIMComponent.ExportBuildingComponent(FullFileName)

 

Message 9 of 11
Anonymous
in reply to: lmc.engineering

Hi @lmc.engineering.

Is it possible to have an option for ucs? I have consistent ucs name of each file.

Message 10 of 11
lmc.engineering
in reply to: Anonymous

Hi @Anonymous 

 

You can export a BIM component with a user coordinate system using the following:

 

Dim oDoc As Document = ThisApplication.ActiveDocument
CompDef = oDoc.ComponentDefinition

Dim oBIMOrientType As BIMComponentOrientationTypeEnum
oBIMOrientType = kUserCoordinateSystemOrientationType

FullFileName = "C:\Temp\Test.adsk"
CompDef.BIMComponent.ExportBuildingComponent(FullFileName)

If you need to create and set the UCS before export, you can use this.

Sub Main()
CreateUCSBy3Points()
End Sub

Sub CreateUCSBy3Points()
	Dim oDoc As Document = ThisApplication.ActiveDocument
    ' Set a reference to the PartComponentDefinition object
    Dim oCompDef As PartComponentDefinition
    oCompDef = oDoc.ComponentDefinition

    Dim oTG As TransientGeometry
    oTG = ThisApplication.TransientGeometry

    ' Create 3 workpoints to define the origin, x-direction and y-direction points
    Dim oWorkPoint1 As WorkPoint
    oWorkPoint1 = oCompDef.WorkPoints.AddFixed(oTG.CreatePoint(2, 0, 0))

    Dim oWorkPoint2 As WorkPoint
    oWorkPoint2 = oCompDef.WorkPoints.AddFixed(oTG.CreatePoint(4, 0, 0))

    Dim oWorkPoint3 As WorkPoint
    oWorkPoint3 = oCompDef.WorkPoints.AddFixed(oTG.CreatePoint(2, 2, 0))

    ' Create an empty definition object
    Dim oUCSDef As UserCoordinateSystemDefinition
    oUCSDef = oCompDef.UserCoordinateSystems.CreateDefinition

    ' Set it to be based on the 3 points
    Call oUCSDef.SetByThreePoints(oWorkPoint1, oWorkPoint2, oWorkPoint3)

    ' Create the UCS
    Dim oUCS As UserCoordinateSystem
    oUCS = oCompDef.UserCoordinateSystems.Add(oUCSDef)
	ExportBIM(oDoc)
End Sub

Sub ExportBIM(oDoc As Inventor.Document)
'Dim oDoc As Document = ThisApplication.ActiveDocument
CompDef = oDoc.ComponentDefinition

Dim oBIMOrientType As BIMComponentOrientationTypeEnum
oBIMOrientType = kUserCoordinateSystemOrientationType

FullFileName = "C:\Temp\Test.adsk"
CompDef.BIMComponent.ExportBuildingComponent(FullFileName)
End Sub

Is this what you were asking?

 

 

Message 11 of 11
AnJanson
in reply to: lmc.engineering

Hi @lmc.engineering,

I found your solution, but I am pretty sure that it does not work.

Your code does not really set the OrientationType, the assignment is missing.

When I try to assign the OrientationType I get an exception.

I have already  created a thread:

https://forums.autodesk.com/t5/inventor-customization/export-rfa-with-ucs/td-p/9465092

Could you please do me a favor and check this issue?

Regards Andreas

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report