Export sheetmetal for fabrication

Linnemann
edited February 2025 in BricsCAD Mechanical

BricsCAD has some nice features to automate sheet-metal

One thing it does not do so well is automate the stuff for fabrication, I know it can do it and write to HTML etc. but my suppliers do not work that way.

Normally we send the dxf file for fabrication and an accompanying pdf.

I've created a custom export function via LISP.

The only thing I cannot get it to do is get the thickness of the local body.

I can get the global thickness value via LISP, but not the local thickness.

So you have to input thickness and the quantity manually.

The code is not tested extensively, but it gives you an idea of how to automate this process.

Is assumes you have a folder called "Laser" in the same folder as the drawing.

(vl-load-com)
(princ "SMEXPORT Loaded") (defun c:smexport (/ feature filenameStr body thickness LastEnt flange material ss ss2)
(setq feature (ssget "_:V"))
(setq flange (car (SmLispGet "FeaturesBySubEntity" feature)))
(setq LastEnt (SmLispGet "SelectEntities" "Top" flange)) (initget 1 "1.5 2 3 4 5 6 8 10 12") (setq thickness(getkword "\nSelect Thickness [1.5/2/3/4/5/6/8/10/12]: ")) (setq nPcs (getint "Amount to produce: ")) (setvar 'nomutt 1) ;(initget 1 "1 2 3 4 _ S235 S355 AISI304L AISI316L") ;(setq material(getkword "\nSelect material [1=S235/2=S355/3=AISI304L/4=AISI316L]: ")) (setq material (BmLispGet "Material" (car (BmLispGet "Components")))) (setq body (SmLispGet "BodyName" (ssname feature 0))) ;(setq body "test") (setq filenameStr (strcat (getvar 'dwgprefix) "//Laser//" (vl-filename-base (getvar "dwgname")))) (setq filenameStr (strcat filenameStr "_" body)) (setq filenameStr (strcat filenameStr "_" thickness "mm_" material "_" (itoa nPcs) "stk")) (command "_smUnfold" "#0,0,0" "#0,0,0" "2D" (strcat filenameStr ".dxf") "2013") (command "_layer" "OFF" "Attributes" "") (command "_layer" "OFF" "Bend Annotations" "") (command "_layer" "OFF" "Bends Down" "") (command "_layer" "OFF" "Defpoints" "") (command "_layer" "OFF" "Bends Up" "") (command "_layer" "OFF" "Overall Dimensions" "") (command "_layer" "ON" "Attributes" "") (command "_layer" "ON" "Overall Dimensions" "") (command "_Style" "" "" "15" "" "" "" "") (setq ss (ssget "_X" '((0 . "DIMENSION")))) (repeat (setq n (sslength ss)) (vla-put-TextHeight (vlax-ename->vla-object (ssname ss (setq n (1- n)))) 15) ); repeat (setq ss2 (ssget "_X" '((0 . "MTEXT")))) (repeat (setq n (sslength ss2)) (setq obj (vlax-ename->vla-object (ssname ss2 (setq n (1- n))))) (vla-put-Height obj 15) (setq posi (+ -60 (* n -15))) (vlax-put-property obj "InsertionPoint" (strcat "0,"(itoa posi)",0")) ); repeat (setvar 'CLAYER "Attributes") (command "_.MTEXT" "0,-80,0" "_Justify" "BL" "_Height" 15 "_none" "@" (strcat "Quantity = " (itoa nPcs) "pcs" ) "") (setvar 'CLAYER "0") (command "_exportpdf" (strcat filenameStr ".pdf") "Y") ;(command "_exportpdf" "" "Y") (command "_layer" "OFF" "Attributes" "") (command "_layer" "OFF" "Bend Annotations" "") (command "_layer" "OFF" "Bends Down" "") (command "_layer" "OFF" "Defpoints" "") (command "_layer" "OFF" "Bends Up" "") (command "_layer" "OFF" "Overall Dimensions" "") (command "_saveas" "DXF" "V" "2013" "5" (strcat filenameStr ".dxf") "Y") (vl-load-com) (vla-SendCommand (vla-get-ActiveDocument (vlax-get-acad-object)) "_.CLOSE ") ;(command "_smexport2d" (strcat (getvar 'dwgprefix) "//" (vl-filename-base (getvar "dwgname")) "_" body ".dxf") "2010") (setvar 'nomutt 0) (princ) )

Comments

  • Linnemann
    edited September 8

    So after some time I found out a way to extract the thickness without having to input manually.

    (vl-load-com)
    (princ "SMEXPORT5 Loaded") (defun c:smexport5 (/ feature filenameStr body thickness LastEnt flange material ss ss2 entObj nPcs n posi obj flatBlock rawThk effRecord)
    ;; 1. Get the sub-entity selection from the user
    (setq feature (ssget "_:V"))
    (if (null feature)
    (progn (princ "\nError: Nothing selected.") (exit))
    ) (setq flange (car (SmLispGet "FeaturesBySubEntity" feature)))
    (setq LastEnt (entlast)) ; Tag the last layout database object before unfolding

    (setq nPcs (getint "\nAmount to produce: "))
    (setvar 'nomutt 1)

    ;; Force-load BricsCAD's mechanical API environment module
    (if (null (member "vl-load-mech" (atoms-family 0))) (vl-load-mech))

    ;; Fetch structural material and body name strings from the assembly
    (setq material (BmLispGet "Material" (car (BmLispGet "Components"))))
    (if (null material) (setq material "UnknownMaterial"))

    (setq body (SmLispGet "BodyName" (ssname feature 0)))
    (if (null body) (setq body "Body"))

    ;; 2. Place Temporary Unfold Block Headlessly at Absolute Origin (0,0,0)
    (setvar 'cmdecho 0)
    (vl-cmdf "_smUnfold" feature '(0.0 0.0 0.0) "K")
    (setvar 'cmdecho 1)

    (setq flatBlock (entlast))
    (setq thickness "unknown") ; Default fallback initialization

    ;; 3. Extract the Mechanical Component Parameter Value from the Placed Block
    (if (not (equal LastEnt flatBlock))
    (progn
    ;; FIXED: Using the exact rawThk variable scoped in the defun header
    (setq rawThk (mech:get-componentparametervalue flatBlock "_SM_THICKNESS"))

    ;; Format the numerical double into a clean string matching your file structure ("4", "1.5", etc.)
    (if (and rawThk (> rawThk 0))
    (setq thickness (rtos rawThk 2 1))
    )
    ;; Wipe the temporary placeholder from the drawing canvas instantly
    (entdel flatBlock)
    )
    )

    ;; Safe manual prompt fallback if the layout engine ever encounters non-sheetmetal bodies
    (if (or (= thickness "unknown") (= thickness "0") (= thickness "0.0") (null thickness))
    (progn
    (setvar 'nomutt 0)
    (initget 1 "1 1.5 2 3 4 5 6 8 10 12")
    (setq thickness (getkword "\nThickness not detected from BDM map. Select manually [1/1.5/2/3/4/5/6/8/10/12]: "))
    (setvar 'nomutt 1)
    )
    (princ (strcat "\n[SUCCESS] Auto-extracted body thickness: " thickness "mm"))
    )

    ;; 4. Construct File Export Names Linked to Core ERP Fields
    (setq filenameStr (strcat (getvar 'dwgprefix) "//Laser//" (vl-filename-base (getvar "dwgname"))))
    (setq filenameStr (strcat filenameStr "_" body))
    (setq filenameStr (strcat filenameStr "_"
    thickness "mm_"
    material "_"
    (itoa nPcs) "stk")) (setvar 'cmdecho 0)
    (vl-cmdf "_smUnfold" feature '(0.0 0.0 0.0) "2D" (strcat filenameStr ".dxf") "2013")
    (setvar 'cmdecho 1) ;; 5. Output Conversions & Layer Scaling Automation
    (command "_layer" "OFF" "Attributes" "")
    (command "_layer" "OFF" "Bend Annotations" "")
    (command "_layer" "OFF" "Bends Down" "")
    (command "_layer" "OFF" "Defpoints" "")
    (command "_layer" "OFF" "Bends Up" "")
    (command "_layer" "OFF" "Overall Dimensions" "")
    (command "_layer" "ON" "Attributes" "")
    (command "_layer" "ON" "Overall Dimensions" "")
    (command "_Style" "" "" "15" "" "" "" "")

    (setq ss (ssget "_X" '((0 . "DIMENSION"))))
    (if ss
    (repeat (setq n (sslength ss))
    (vla-put-TextHeight (vlax-ename->vla-object (ssname ss (setq n (1- n)))) 15)
    )
    )

    (setq ss2 (ssget "_X" '((0 . "MTEXT"))))
    (if ss2
    (repeat (setq n (sslength ss2))
    (setq obj (vlax-ename->vla-object (ssname ss2 (setq n (1- n)))))
    (vla-put-Height obj 15)
    (setq posi (+ -60 (* n -15)))
    (vlax-put-property obj "InsertionPoint" (strcat "0,"(itoa posi)",0"))
    )
    )

    (setvar 'CLAYER "Attributes")
    (command "_.MTEXT" "0,-80,0" "_Justify" "BL" "_Height" 15 "_none" "@" (strcat "Quantity = " (itoa nPcs) "pcs" ) "")
    (setvar 'CLAYER "0")

    ;; Export manufacturing profiles and clean geometry states
    (command "_exportpdf" (strcat filenameStr ".pdf"))
    (command "_layer" "OFF" "Attributes" "")
    (command "_layer" "OFF" "Bend Annotations" "")
    (command "_layer" "OFF" "Bends Down" "")
    (command "_layer" "OFF" "Defpoints" "")
    (command "_layer" "OFF" "Bends Up" "")
    (command "_layer" "OFF" "Overall Dimensions" "")
    (command "_saveas" "DXF" "V" "2013" "5" (strcat filenameStr ".dxf") "Y")

    ;; Close out drawing environment session cleanly
    (vla-SendCommand (vla-get-ActiveDocument (vlax-get-acad-object)) "_.CLOSE ")
    (setvar 'nomutt 0)

    (princ) )

  • Just a suggestion,

    (command "_layer" "OFF" "Attributes" "Bend Annotations" "Bends Down" "Defpoints" "Bends Up" "Overall Dimensions" "")

    You could also have a little defun that turns layers on or off if doing this often in a program.

    (setq lays '("Attributes" "Bend Annotations" "Bends Down" "Defpoints" "Bends Up" "Overall Dimensions"))

    (defun layonoff (lst onoff / )
    (foreach val lst
    (if (= onoff 1)
    (command "_layer" "OFF" val) ; 1 for off
    (command "_layer" "ON" val) ; 0 for ON
    )
    )

    (layonoff lays 0)