- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Hopefully someone can help me with exporting a surface to a dxf-file.
At this moment I'm exporting a sketch of a unfolded sheetmetal surface with some holes to a dxf-file. However when the number of holes is changing the sketch is not automatically updated and therefore not all the holes are included in the dxf-file. So perhaps there is a trick to automatically update the projected geometry of a surface in a sketch?
Other option is to export a surface, but I cant achieve this. I have made a offset surface and this surface is automatically update when the number of holes has changed, so far so good, however I'm struggling with the code to export it to DXF, hopefully someone can help.
Maybe there is another way to go?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
I don't understand why you not export the unfolded part itself. You do not need to use a sketch. Try this simpliest version of export:
Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oDataIO As DataIO = oDoc.ComponentDefinition.DataIO
Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=R12&OuterProfileLayer=Outer&TrimCenterlinesAtContour=True"
Call oDataIO.WriteDataToFile( sOut, "C:\temp\flat.dxf")
Or am I missunderstanding your question?
R. Krieg
RKW Solutions
www.rkw-solutions.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks for your reply!
In this case, the cut profile is not perpendicular to the surface: bottom sheet contour will be different from top side. With exporting the unfolded model you get all lines from the bottom and top side of the sheet, I don't want this. Therefore I would like to export from a predefined surface or sketch.
At this moment I'm struggling with this code:
Feature.IsActive("Unfold3") = True
Dim fileName As String = ThisDoc.PathAndFileName(False) & ".dxf"
Dim doc As PartDocument = ThisDoc.Document
Dim surface As SurfaceBody = doc.ComponentDefinition.SurfaceBodies.Item("Export surface")
Dim sOut As String = "DXF"
surface.DataIO.WriteDataToFile(sOut, fileName)For a sketch it is working but not for a surface.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Thanks, your code works fine, but it is not quite what I want to achieve.
I want to avoid manually choosing a surface because someone else could select the wrong side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
It's quite difficult to understand what you are doing exactly. Is it possible to post a demofile?
Anyway, Inventor can define an A-Side for flat pattern. Usually this is not changed by users in parametric parts where users change only parameters like length, width, hole count or something similar. The A-Side object has a face property which could be used.
Can you proof if the A-Side definition can be used to "mark" your face? If so, we can start to code the script.
R. Krieg
RKW Solutions
www.rkw-solutions.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
With the A-side you are mentioning the Stationary Reference face (A)? This reference face is not changed in the part, so I assume you can use it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
We can use the A-Side definition only if the model is unfolded. If the user suppress this feature or refold the model, the face is not planar and useless. Is there a reason for not using the flat pattern? If we create a flat pattern, we can obtain the top face for export. It's the face you look at if the flat pattern environment is activated.
I've added both possibilities to the script. If an A-Side definition is found and no flat pattern exist, the A-Side definition is used. If a flat pattern exist, the top face of flat pattern is used.
Can you try it out?
Private Sub Main()
Dim oApp As Inventor.Application = ThisApplication
'check that this active document is a part file
If oApp.ActiveDocument.DocumentType <> kPartDocumentObject Then
Call MsgBox("Please open a part document", "iLogic")
Exit Sub
End If
Dim oPartDoc As PartDocument = oApp.ActiveDocument
If Not oPartDoc.ComponentDefinition.Type = ObjectTypeEnum.kSheetMetalComponentDefinitionObject
Call MsgBox("Part document must be a sheet metal part", "iLogic")
Exit Sub
End If
Dim oCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
Dim oASide As Face
If oCompDef.ASideDefinitions.Count > 0 Then
oASide= oCompDef.ASideDefinitions.Item(1).ASideFace
End If
If oCompDef.HasFlatPattern = True Then
oASide = oCompDef.FlatPattern.TopFace
End If
If oASide Is Nothing Then
Call MsgBox("Please create an A-Side definition or a flat pattern first", "iLogic")
Exit Sub
End If
Dim sFolder = ThisDoc.Path & "\DXF\"
Dim sFilename = ThisDoc.FileName(False)
Dim sFullFilename As String = sFolder & sFilename & ".dxf"
Try
Dim oDirInfo As System.IO.DirectoryInfo= System.IO.Directory.CreateDirectory (sFolder)
Catch
Call MsgBox("Could not create target folder. Missing write access?", "ilogic")
Exit Sub
End Try
'add filename to memory for file save dialog
Dim Cm As CommandManager = oApp.CommandManager
Cm.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, sFullFilename )
Dim oSelectSet As SelectSet = oPartDoc.SelectSet
oPartDoc.SelectSet.Clear()
Call oPartDoc.SelectSet.Select(oASide)
Dim oCtrlDef As ButtonDefinition
oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("GeomToDXFCommand")
Call oCtrlDef.Execute
oPartDoc.SelectSet.Clear()
End Sub
R. Krieg
RKW Solutions
www.rkw-solutions.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Thanks this is working!
Only thing which is not working is the text message when a A-side and flat pattern doesn't exist.
But that doesn't matter for me, problem is solved for me, thanks again!