We would need to export assembly files to DXF (1:1 scale) No mass export but in the idea, it would rather be an export under design
First problem, as you may know, it is impossible to directly export an assembly to DXF (at least to my knowledge in 2017) We may have the possibility to make a macro, to export to a part and then export to DXF, here second problem because we have no knowledge about macros
At our disposal, we have myCADtools or myPDMtools But we don't really know all the capabilities of these tools.
Do you have any leads to give? Thanks in advance, Séb
Thank you ac cobra 427 for your file But I can't launch it, nothing runs I have the impression, no PDF file is generated And in terms of macro editing, I'm a marble
Edit: I just understood that you need a drw plan already created As a result, the macro executes
It is not possible to export an assembly to a dxf, it is necessary to go through a drawing with the choice of views to be exported.
Of course, the MEP will have to be re-registered as it progresses.
Not sure that a macro will save you a lot of time on the issue. It's as quick to put down your 3 views and export yourself ^me as it is to press a button and let the macro do its thing.
For the MyCad tool, same thing, not really of interest for the subject
Thank you very much gwygwy This is already a tremendous step forward!
DXF from assembly generates correctly I just have to get to position the assembly in 0,0,0 (by necessarily the origin of the 3D) And to rename the file
Is it possible from a macro to have a dialog box to write the name of the desired file? or retrieve the name of a SW property of the file?
So if I want the generated DXF to be named by "myValue" Do I need to modify the Part.SaveAs block in the macro sent by gwygwy ?
'--- Saving the dxf and closing the temporary
MEP Part.SaveAs PathNoExtension & ". DXF"
Part.ClearSelection2 True
Set Part = swApp.ActiveDoc
swApp.CloseDoc swDraw.GetTitle 'Quits without backing up the MEP.
.
I am also having difficulty positioning my assembly in 0,0,0 By default, the origin of the DXF is always in the center of my assembly
Yes, you need to modify the Part.SaveAs block to recalculate the PathNoExtension variable.
A small example:
Dim maValeur As String
maValeur = InputBox("Ma question ?", "Mon titre", "Ma valeur par défaut")
Dim FilePath As String
Dim FileTitle As String
Dim PathSize As Long
Dim TitleSize As Long
Dim PathNoExtension As String
FilePath = Part.GetPathName
FileTitle = Part.GetTitle
PathSize = Strings.Len(FilePath)
TitleSize = Strings.Len(FileTitle)
PathNoExtension = Strings.Left(FilePath, PathSize - TitleSize)
MsgBox PathNoExtension & maValeur & ".dxf"
The result is really not bad, All that remains is to position the whole thing in 0,0,0 And to record the DXF in a file in raw and not to the impalement of the 3D
OK, so let's see if something like the following suits you:
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim retval As String
Dim FilePath As String
Dim FileTitle As String
Dim PathSize As Long
Dim TitleSize As Long
Dim PathNoExtension As String
Dim maValeur As String
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
'--- Création du nom du fichier
FilePath = swModel.GetPathName
FileTitle = swModel.GetTitle
PathSize = Strings.Len(FilePath)
TitleSize = Strings.Len(FileTitle)
PathNoExtension = Strings.Left(FilePath, PathSize - TitleSize)
maValeur = InputBox("Veuillez indiquer le nom du fichier dxf ?", "Macro Asm To DXF", "MonFichier")
PathNoExtension = PathNoExtension & maValeur & ".dxf"
'--- Calcul du décalage de l'origine
Dim vBox As Variant
Dim swAssy As SldWorks.AssemblyDoc
Dim X_max As Double
Dim X_min As Double
Dim Y_max As Double
Dim Y_min As Double
Dim Z_max As Double
Dim Z_min As Double
If swModel.GetType() <> swDocASSEMBLY Then Exit Sub
Set swAssy = swModel
vBox = swAssy.GetBox(swBoundingBoxIncludeRefPlanes)
X_max = vBox(3)
X_min = vBox(0)
Y_max = vBox(4)
Y_min = vBox(1)
Z_max = vBox(5)
Z_min = vBox(2)
Dim decalX As Double
Dim decalY As Double
decalX = (X_max - X_min) / 2
decalY = (Y_max - Y_min) / 2
'--- Création de la mise en plan
retval = swApp.GetUserPreferenceStringValue(swDefaultTemplateDrawing)
Set swDraw = swApp.NewDocument(retval, 0, 0, 0)
'--- Insertion de la vue
Set swView = swDraw.CreateDrawViewFromModelView3(swModel.GetPathName, "*Face", decalX, decalY, 0)
'--- Rend invisible les annotations de plis
swView.ShowSheetMetalBendNotes = False
'--- Force la vue à l'échelle 1:1
Dim swSheet As Sheet
Dim status As Boolean
Set swView = swDraw.GetFirstView
Set swSheet = swDraw.GetCurrentSheet
status = swSheet.SetScale(1, 1, True, True)
'--- Sauvegarde du dxf et fermeture de la MEP temporaire
swDraw.SaveAs PathNoExtension & ".DXF"
swDraw.ClearSelection2 True
swApp.CloseDoc swDraw.GetTitle
End Sub
I didn't handle saving the dxf file in another folder...
The principle is to calculate the dimensions of the "BoundingBox" of the assembly and to move the view by half of them since by default the origin of the view is the center of the assembly.