map xml to user parameters in ilogic or vb

map xml to user parameters in ilogic or vb

Anonymous
Not applicable
1,612 Views
1 Reply
Message 1 of 2

map xml to user parameters in ilogic or vb

Anonymous
Not applicable

Hello,

 

I am trying parse and import parameters from an .xml file into inventor. I've attached the file for reference.

 

The file I've attached is an output from a home-grown design program for one of the products we use. It spits out this file to be read by our ERP system downstream of Engineering. I would also like to use it to populate my model with parameters so the drawing is generated automatically. 

 

For example, the material_thickness nodes correspond to steel plate thicknesses, and the lenght/width correspond to steel plate rectangular dimensions. There are also bolt diameters and other parameters I would like to read.

 

I know there is an out of the box import/export xml parameters, but from what I understand the xml has to be formatted a specific way. I would like to map this existing schema to user parameters in my model. If someone could send me an ilogic or vb code snippet that would be great.

 

Thanks

Matt

0 Likes
1,613 Views
1 Reply
Reply (1)
Message 2 of 2

dean.morrison
Advocate
Advocate

Matt,

 

I do a similar thing (import to inventor from xml)

 

My xml format may be slightly different, but here is some of the code that i use.

I use VBA to do this - example below.

I hope you can figure out what you need to change, based on this example.

 

Dean.

-----------------------------------------------------------------------------

 

'I have a reference to Microsoft XML v3.0

 

xmlfile = "C:\xml.xml" 'Path to xml file

Set objXML = New MSXML2.DOMDocument

objXML.Load xmlfile

 

'For a normal node

Set xmlElem = objXML.selectSingleNode("//NodeName")
If Not xmlElem Is Nothing Then
oNodeName = xmlElem.Text
End If

 

'For a node with children

Set xmlElem = objXML.selectNodes("//NodeNamewithchildren")
If Not xmlElem Is Nothing Then
oNodeNamewithchildren = xmlElem.ChildNodes.Item(0).Text 'index for child node
End IF


'To apply the xml node value to a User Paramater

Dim oFileLocations As FileLocations
Set oFileLocations = ThisApplication.FileLocations

Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents.Open(oFileLocations.Workspace & "/Part.ipt")

Dim oPartCompDef As PartComponentDefinition
Set oPartCompDef = oPartDoc.ComponentDefinition

Dim oParams As UserParameters
Set oParams = oPartCompDef.Parameters.UserParameters

oParams.Item("ParameterName").Expression = oNodeName

oParams.Item("ParameterName").Expression = oNodeNamewithchildren

oPartDoc.Save2 (True)
oPartDoc.Close