Import .obj into assembly and set its units.

Import .obj into assembly and set its units.

dylanTEV9W
Advocate Advocate
1,907 Views
10 Replies
Message 1 of 11

Import .obj into assembly and set its units.

dylanTEV9W
Advocate
Advocate

Hi everyone I'm trying to import an .obj into an assembly using vb.net. I need to change its units from the default it comes in as inches and I want it to be meters. 

 

This is the code I have so far. 

 

Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click

 

Dim inventor = _invApp.Documents 'access the inventor document subclass

 

inventor.Open("D:\Project Files\Inventor\CAD Files\assembly.iam", True)

 

'Get application information.

Dim assembly_doc As AssemblyDocument ' get the active part document

assembly_doc = _invApp.ActiveDocument 'set part_doc as the active part document

Dim assembly_component As AssemblyComponentDefinition 'set the assembly component definition.

assembly_component = assembly_doc.ComponentDefinition

Dim trans_geo As TransientGeometry 'get transient geometry from the application

trans_geo = _invApp.TransientGeometry 'set trans_geo as Transient Geometry object

 




'define part file names

Dim part1_str As String = "D:\Project Files\Test Files\part1.obj"

 

 

 

'Now that the assembly file is open and active add the part

'first we need to make a position and orientation matrix and file name to be used when its added to the assembly.

 

Dim left_matrix As Matrix = trans_geo.CreateMatrix 'Create a matrix for positioning the foot.

Call left_matrix.SetToRotation(0, trans_geo.CreateVector(0, 0, 1), trans_geo.CreatePoint(0, 0, 0)) 'set the matrices rotation component.

Call left_matrix.SetTranslation(trans_geo.CreateVector(-0.3, 0, 0), True) 'set the matrices translation component.

 

 

 


'Open the part

Dim comp_occurence As Inventor.ComponentOccurrence 'Define the component occurence.

comp_occurence = assembly_doc.ComponentDefinition.Occurrences.Add(part1_str, left_matrix)

 

End Sub

 

0 Likes
Accepted solutions (1)
1,908 Views
10 Replies
Replies (10)
Message 2 of 11

clutsa
Collaborator
Collaborator

what if you change the assembly doc unit type before you add the componentOccurrence?

Dim UOM = assembly_doc.UnitsOfMeasure
UOM.LengthUnits = UnitsTypeEnum.kMeterLengthUnits
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 3 of 11

JamieVJohnson2
Collaborator
Collaborator

Help us narrow it down so we can give better advice.

 

You stated the original .obj is in Inches units, and  your assembly is in Meters... I see two questions to ask here:

Do you need to scale the object? 25.4in/meters x original, or 2.54in/cm x original

Do you only need to change the new part file's display units? 

 

Inventor automatically recognizes it as inches and scales it automatically, but you still need document units to say meters.  Or Inventor doesn't recognize the units and doesn't scale it properly leaving it up to you to fix (before or after import).

 

FYI, Inventor processes in centimeters, so via the api all values will respond in centimeters regardless of document properties (unless you convert them).

 

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 4 of 11

dylanTEV9W
Advocate
Advocate

Sorry I should have explained better. The parts that I'm trying to import are .obj scans in meters. But they're coming in way scaled down because I assume that inventor is either defaulting to cm or inches (I think it's inches because that's the base unit on the part files after I export them.) I want to bring them into the inventor assembly at the same scale they were scanned in (meters). I'll try setting the units of measure in the api to meters, I already set the units to meters in the assembly document under doc. settings.  

0 Likes
Message 5 of 11

dylanTEV9W
Advocate
Advocate

I tried running the code snippet you posted prior to importing the .obj's into the assembly file, the .obj's are still coming in scaled way down.

0 Likes
Message 6 of 11

JamieVJohnson2
Collaborator
Collaborator

Along this same train of thought, if you explicitly control the translator/importer add-in, there is a Translator Option called ImportUnit that you can set.  (search API for TranslatorAddIn Object \ Translator Options).

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 7 of 11

dylanTEV9W
Advocate
Advocate

I will try the Translator Option ImportUnit and see if I can make that work with the assembly document. 

0 Likes
Message 8 of 11

dylanTEV9W
Advocate
Advocate

I'm trying to use the translator addin but I'm running into the same issue that I've had with it before that pushed me to try and make the add occurence to assembly code work instead. The issue is that it seems like each translator has a unique class ID for example the class ID for a .stl is {81CA7D27-2DBE-4058-8188-9136F85FC859}. It seems like there is an example program for most of the common 3D file formats with the exception of .obj files does anyone know what the class ID for a .obj is?

0 Likes
Message 9 of 11

JamieVJohnson2
Collaborator
Collaborator
Accepted solution

Ask and you shall receive... Merry Christmas


For i = 1 To invApp.ApplicationAddIns.Count() Debug.Print(invApp.ApplicationAddIns.Item(i).DisplayName) Debug.Print(invApp.ApplicationAddIns.Item(i).ClassIdString) Next

 

Translator: SAT
{89162634-02B6-11D5-8E80-0010B541CD80}
Routed Systems: Tube & Pipe
{4D39D5F1-0985-4783-AA5A-FC16C288418C}
Translator: STEP
{90AF7F40-0C01-11D5-8E83-0010B541CD80}
Translator: IGES
{90AF7F44-0C01-11D5-8E83-0010B541CD80}
Translator: CATIA V5 Product Export
{8A88FC01-0C32-4B3E-BE12-DDC8DF6FFF18}
Translator: DWG
{C24E3AC2-122E-11D5-8E91-0010B541CD80}
Translator: DXF
{C24E3AC4-122E-11D5-8E91-0010B541CD80}
Assembly Bonus Tools
{0BB5AE99-15A3-4B00-9731-210ED5A4E7B2}
GeneralTools
{95413AE5-1C63-4373-A614-2649F5BF8AA6}
iLogic
{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}
Translator: STL Import
{81CA7D27-2DBE-4058-8188-9136F85FC859}
Simulation: Dynamic Simulation
{24307C2D-2E7F-486F-94A0-0B45E11CB3F6}
Translator: DWF
{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}
Translator: PDF
{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}
Translator: DWFx
{0AC6FD97-2F4D-42CE-8BE0-8AEA580399E4}
Translator: CATIA V5 Part Export
{2FEE4AE5-36D3-4392-89C7-58A9CD14D305}
Mold Design
{24E39891-3782-448F-8C33-0D8D137148AC}
Translator: RVT
{2058EF4F-37A3-4B57-A322-B4E79E7D53E4}
Translator: Parasolid Text
{8F9D3571-3CB8-42F7-8AFF-2DB2779C8465}
Translator: Fusion
{C6B37B88-3CFA-4521-9873-E087B8626C44}
EDM Addin
{48B682BC-42E6-4953-84C5-3D253B52E77A}
Inventor Vault
{48B682BC-42E6-4953-84C5-3D253B52E77B}
BIM Simplify
{71019C12-43F6-4C11-BA7A-AD9BDBC5EA0C}
3d Annotation
{F3FB67F9-57B9-4DEE-A1EC-29A6970F603D}
FCADTransServer
{BE52A5E7-58D8-4E3C-A887-06A4C8F29568}
Autodesk IDF Translator
{6C5BBC04-5D6F-4353-94B1-060CD6554444}
Simulation: Frame Analysis
{4E7C0152-6140-419F-B677-0466F03F013D}
Content Center
{3D88D7B5-6DD8-4205-A2B5-2B51F7BF74A7}
Translator: SolidWorks
{402BE503-725D-41CB-B746-D557AB83BAF1}
Translator: Pro/ENGINEER Granite
{66CB2667-73AD-401C-A531-64EC701825A1}
Inventor Studio
{F3D38928-74D1-4814-8C24-A74CE8F3B2E3}
Additive Manufacturing
{4E2D52FB-8288-4427-B912-20EF97F073C9}
Translator: NX
{93D506C4-8355-4E28-9C4E-C2B5F1EDC6AE}
Design Accelerator
{BB8FE430-83BF-418D-8DF9-9B323D3DB9B9}
ESKD Support
{005B21FC-8537-4926-9F57-3A3216C294C3}
Auto Limits
{F330512C-8773-4A60-A0D3-E3CDA0B9ED0D}
Configurator 360
{90A53562-92D0-48E1-82C1-48507F10DA73}
Translator: SMT
{B4ECC5EB-9507-46E5-87FB-EBB9479CE1DF}
Translator: OBJ Import
{C420F7E4-98FD-4A57-BC1E-04D1D683EFDF}
Screencast Recorder
{1EA1759D-A1A8-4300-B428-93B91A25F43E}
Frame Generator
{AC211AE0-A7A5-4589-916D-81C529DA6D17}
Shared Views
{71C28F1E-B01A-430A-96DD-2C36EA4C29BE}
Translator: SVF
{C200B99B-B7DD-4114-A5E9-6557AB5ED8EC}
Translator: Parasolid Binary
{A8F8F8E5-BBAB-4F74-8B1B-AC011251F8AC}
BIM Content
{842004D5-C360-43A8-A00D-D7EB72DAAB69}
Routed Systems: Cable & Harness
{C6107C9D-C53F-4323-8768-F65F857F9F5A}
iCopy
{A2BE2CFE-CECC-4A49-BD04-A90939D1EB07}
Translator: Pro/ENGINEER and Creo Parametric
{46D96B7A-CF8A-49C9-8703-2F40CFBDF547}
Content Center Item Translator
{A547F528-D239-475F-8FC6-8F97C4DB6746}
Translator: Solid Edge
{E2548DAF-D56B-4809-82B9-5F670E6D518B}
Translator: Pro/ENGINEER Neutral
{8CEC09E3-D638-4E8F-A6E1-0D1E1A5FC8E3}
Anark 3D PDF Publishing
{3EE52B28-D6E0-4EA4-8AA6-C2A266DEBB88}
DrawingTools
{48A74AAC-E196-4AF0-9EC2-28C7C5150645}
Translator: CATIA V4 Import
{C6ACD948-E1C5-4B5B-ADEE-3ED968F8CB1A}
Translator: Rhino
{2CB23BF0-E2AC-4B32-B0A1-1CC292AF6623}
Interactive Tutorial
{4D9C80FE-E70F-4C29-B6C7-8A5AC3F40EB2}
Drag & Drop Interoperability
{B95D705C-E915-4A5B-A498-E73AC98923A2}
Translator: CATIA V5 Import
{8D1717FA-EB24-473C-8B0F-0F810C4FC5A8}
Simulation: Stress Analysis
{B3D04494-EDD2-4FDC-9EC2-30BAF8D6B77B}
Autodesk DWF Markup Manager
{55EBD0FA-EF60-4028-A350-502CA148B499}
Presentations
{6E14DFA9-F418-4111-9F89-BA957482E98F}
Translator: JT
{16625A0E-F58C-4488-A969-E7EC4F99CACD}
Translator: Alias
{DC5CD10A-F6D1-4CA3-A6E3-42A6D646B03E}
Translator: OBJ Export
{F539FB09-FC01-4260-A429-1818B14D6BAC}
Translator: STL Export
{533E9A98-FC3B-11D4-8E7E-0010B541CD80}

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 10 of 11

dylanTEV9W
Advocate
Advocate

Thank you Sir! I didn't realize you could print out the the code like that. Merry Christmas to you to!

0 Likes
Message 11 of 11

dylanTEV9W
Advocate
Advocate

I'm also going to drop this link here in case anyone else comes across this. 

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-25D24E28-7517-4903-8AEE-123F8C71A89E

 

0 Likes