Inserting ACAD DFX into Sketch of a part file

Inserting ACAD DFX into Sketch of a part file

Daan_M
Collaborator Collaborator
417 Views
3 Replies
Message 1 of 4

Inserting ACAD DFX into Sketch of a part file

Daan_M
Collaborator
Collaborator

Hi,

 

I'm trying to insert a DFX file into a sketch of a part file, Unfortunatly not everything in my DFX file appears.

I think some layers are missing or something.

 

Here is my DFX when i open it

Daan_M_0-1699624324599.png

 

Here is the result in the Part file

Daan_M_1-1699624819878.png

 

 

Code;

 

 

Dim oLaserTemplateLoc = "Partfile.ipt"
Dim oPart As PartDocument = ThisApplication.Documents.Open(oLaserTemplateLoc, True)
oPart.Activate
Dim oPCD As PartComponentDefinition = oPart.ComponentDefinition

Dim oDXFTranslator As TranslatorAddIn
    oDXFTranslator = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") 

    Dim oDataMedium As DataMedium
    oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
    oDataMedium.FileName = "DFX Location"
 
    Dim oTranslationContext As TranslationContext
    oTranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
    oTranslationContext.Type = kFileBrowseIOMechanism
    
	Dim oPlaneXZ As WorkPlane = oPCD.WorkPlanes.Item(2) 
    Dim oSketch As PlanarSketch
    oSketch = oPCD.Sketches.Add(oPlaneXZ)

    oSketch.Edit
    oTranslationContext.OpenIntoExisting = oSketch
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    oOptions.Add ("FileUnits", "Millimeters")
    Call oDXFTranslator.Open(oDataMedium, oTranslationContext, oOptions, oPart)
	oSketch.ExitEdit

 

 

 

0 Likes
Accepted solutions (1)
418 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor

I could not test this but you might have some luck with the DWG import options. According to help, there is the option "SelectedLayers ". This specifies the layer names to import. The names are comma delimited. 

JelteDeJong_0-1699648357715.png

https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-25D24E28-7517-4903-8AEE-123F8C71A89E&v=In...

Dim oLaserTemplateLoc = "Partfile.ipt"
Dim oPart As PartDocument = ThisApplication.Documents.Open(oLaserTemplateLoc, True)
oPart.Activate
Dim oPCD As PartComponentDefinition = oPart.ComponentDefinition

Dim oDXFTranslator As TranslatorAddIn
    oDXFTranslator = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") 

    Dim oDataMedium As DataMedium
    oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
    oDataMedium.FileName = "DFX Location"
 
    Dim oTranslationContext As TranslationContext
    oTranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
    oTranslationContext.Type = kFileBrowseIOMechanism
    
	Dim oPlaneXZ As WorkPlane = oPCD.WorkPlanes.Item(2) 
    Dim oSketch As PlanarSketch
    oSketch = oPCD.Sketches.Add(oPlaneXZ)

    oSketch.Edit
    oTranslationContext.OpenIntoExisting = oSketch
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    oOptions.Add ("FileUnits", "Millimeters")
    oOptions.Add ("SelectedLayers", "YOUR,LAYER,NAMES,HERE")
    Call oDXFTranslator.Open(oDataMedium, oTranslationContext, oOptions, oPart)
	oSketch.ExitEdit

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 4

Daan_M
Collaborator
Collaborator

@JelteDeJong Thank you for the advice.

 

I added the following line in my code, but still only the text gets added onto the .ipt file and not the lines:

 

oOptions.Add ("SelectedLayers", "0")

 

When i check the .dwg, the layer with lines should be "0"?

 

Daan_M_0-1699865976418.png

 

The same goes for the text:

Daan_M_1-1699866033813.png

I attached my .dwg file.

 

Curious what i'm doing wrong

 

0 Likes
Message 4 of 4

JelteDeJong
Mentor
Mentor
Accepted solution

In your OP you wrote that you wanted to import a DXF. But you posted a DWG file. On closer inspection, I discovered that the options that you use are also for DWG files. But the GUID is for the DXF translator (I did not see any import options for the DXF translator btw.) Anyway, if you want to import DWG files you need to use a different GUID.  This iLogic rule worked for me.

 Dim oDXFTranslator As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}") 
'Dim oDXFTranslator As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

Dim oPart As PartDocument = ThisDoc.Document
Dim oPCD As PartComponentDefinition = oPart.ComponentDefinition

Dim oPlaneXZ As WorkPlane = oPCD.WorkPlanes.Item(2)
Dim oSketch As PlanarSketch = oPCD.Sketches.Add(oPlaneXZ)
oSketch.Edit()

Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
oDataMedium.FileName = "D:\forum\Laserding.dwg"

Dim oTranslationContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
oTranslationContext.Type = kFileBrowseIOMechanism
oTranslationContext.OpenIntoExisting = oSketch

Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
oOptions.Add("SelectedLayers", "0")
oOptions.Add("InvertLayersSelection", True)
oOptions.Add("FileUnits", "Centimeters")
oOptions.Add("ConstrainEndPoints", True)


oDXFTranslator.Open(oDataMedium, oTranslationContext, oOptions, oDoc)
oSketch.ExitEdit()
 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com