SMREPAIR via API
Hello,
I wan´t to make a script to batch repair sheetmetal files made in Revit.
A lot of files have errors that prevent them from being unfolded (see attached example).
The errors are not severe and easily fixed with the SMREPAIR function.
But in order to complete the repair action I need to select a solid face.
With the mouse this is an easy task, but I can't figure out how to do it via a script.
Is there a way to run SMREPAIR without user input?
The export to dxf has a similar problem, but you have fixed it in the sm assembly export.
So it should be possible. I hope you can help me.
With kind regards,
Robert
Comments
-
The challenge with a lot of BricsCAD Mechanical commands is that they don't really follow traditional BricsCAD/AutoCAD command methods and sequences. SMREPAIR is an example in that it offers selection options within the command, but won't accept selections made that way.
The developers reference gives a hint on what is required with Calling SheetMetal Commands from LISP code.
Simplistically you could use the following LISP calls to run SMREPAIR
(SmLispGet "SelectEntities" "Top" "Flange_1") (command "._SMREPAIR")
This will work for the first sheet metal entity found, assuming it has a flange called "Flange_1"
Taking this a bit further you can get it to work with multiple sheet metal entities using different flange names.
The attached LISP has two commands:
1. MYSMREPAIR will allow you to select sheet metal entities to run SMREPAIR on.
2. SMREPAIRALL will automatically run SMREPAIR on ALL sheet metal entities found in the drawing.Note the function called by both commands simply uses the first sheet metal feature found in creating the selection passed to SMREPAIR. This worked for all the objects I tested on, but may need further refinement. You should get a message if it does fail.
(defun SMREPAIRER (sset / ctr adoc ent 1stFeat bname chkerr) (setq ctr 0) (setq adoc (vla-get-activedocument (vlax-get-acad-object))) (vla-endundomark adoc) (vla-startundomark adoc) (acet-sysvar-set '("CMDECHO" 0 )) (foreach ent (vle-selectionset->list sset) (cond ((SmLispGet "HasEntityFeatures" ent) (setq 1stFeat (car (SmLispGet "FeaturesByEntity" ent))) (setq bname (SmLispGet "BodyName" ent)) (princ (strcat "\nAttempting SMREPAIR on " bname " ")) (SmLispGet "SelectEntities" "Top" 1stFeat) ; select first sheet metal feature (command "._SMREPAIR") ; run repair ;Check if there were issues (setq chkerr (getvar "errno")) (cond ((= 0 chkerr)(princ "Success!")(setq ctr (1+ ctr))) ; No issues ((/= 0 chkerr)(princ (strcat "Failed with error: " (itoa chkerr)))) ; if issue report the error no ) ) (T (Princ (strcat "\nEntity with handle " (vle-entget 5 ent) " is NOT sheet metal"))) ) ) (acet-sysvar-restore) (vla-endundomark adoc) ctr ) ; SMREPAIRALL ; Runs SMREPAIR on all sheet metal entities found in the current drawing (defun C:SMREPAIRAll ( / sset ret) (cond ((and (SmLispGet "HasSheetMetalContext")(setq sset (ssget "X" '((0 . "3DSOLID"))))) (setq ret (SMREPAIRER sset)) (princ (strcat "\nSMREPAIR ran succesfully on " (itoa ret) " Sheet Metal entities")) ) (T (princ "\nNo Sheet Metal entities found.")) ) (prin1) ) ; MYSMREPAIR ; Runs SMREPAIR on user selected sheet metal entities (defun C:MYSMREPAIR ( / sset ret) (cond ((SmLispGet "HasSheetMetalContext") (princ "\nSelect Sheet metal bodies to repair") (setq sset (ssget '((0 . "3DSOLID")))) (cond (sset (setq ret (SMREPAIRER sset)) (princ (strcat "\nSMREPAIR ran succesfully on " (itoa ret) " Sheet Metal entities")) ) (T (princ "\nNo Sheet Metal entities selected")) ) ) (T (princ "\nNo Sheet Metal entities present")) ) (prin1) ) (princ "\nSheet Metal Repairer loaded, Command(s): MYSMREPAIR SMREPAIRALL") (princ)
Regards,
Jason Bourhill
BricsCAD V22 Ultimate
CAD Concepts0 -
The challenge with a lot of BricsCAD Mechanical commands is that they don't really follow traditional BricsCAD/AutoCAD command methods and sequences. SMREPAIR is an example in that it offers selection options within the command, but won't accept selections made that way.
The developers reference gives a hint on what is required with Calling SheetMetal Commands from LISP code.
Simplistically you could use the following LISP calls to run SMREPAIR
(SmLispGet "SelectEntities" "Top" "Flange_1") (command "._SMREPAIR")
This will work for the first sheet metal entity found, assuming it has a flange called "Flange_1"
Taking this a bit further you can get it to work with multiple sheet metal entities using different flange names.
The attached LISP has two commands:
1. MYSMREPAIR will allow you to select sheet metal entities to run SMREPAIR on.
2. SMREPAIRALL will automatically run SMREPAIR on ALL sheet metal entities found in the drawing.Note the function called by both commands simply uses the first sheet metal feature found in creating the selection passed to SMREPAIR. This worked for all the objects I tested on, but may need further refinement. You should get a message if it does fail.
(defun SMREPAIRER (sset / ctr adoc ent 1stFeat bname chkerr) (setq ctr 0) (setq adoc (vla-get-activedocument (vlax-get-acad-object))) (vla-endundomark adoc) (vla-startundomark adoc) (acet-sysvar-set '("CMDECHO" 0 )) (foreach ent (vle-selectionset->list sset) (cond ((SmLispGet "HasEntityFeatures" ent) (setq 1stFeat (car (SmLispGet "FeaturesByEntity" ent))) (setq bname (SmLispGet "BodyName" ent)) (princ (strcat "\nAttempting SMREPAIR on " bname " ")) (SmLispGet "SelectEntities" "Top" 1stFeat) ; select first sheet metal feature (command "._SMREPAIR") ; run repair ;Check if there were issues (setq chkerr (getvar "errno")) (cond ((= 0 chkerr)(princ "Success!")(setq ctr (1+ ctr))) ; No issues ((/= 0 chkerr)(princ (strcat "Failed with error: " (itoa chkerr)))) ; if issue report the error no ) ) (T (Princ (strcat "\nEntity with handle " (vle-entget 5 ent) " is NOT sheet metal"))) ) ) (acet-sysvar-restore) (vla-endundomark adoc) ctr ) ; SMREPAIRALL ; Runs SMREPAIR on all sheet metal entities found in the current drawing (defun C:SMREPAIRAll ( / sset ret) (cond ((and (SmLispGet "HasSheetMetalContext")(setq sset (ssget "X" '((0 . "3DSOLID"))))) (setq ret (SMREPAIRER sset)) (princ (strcat "\nSMREPAIR ran succesfully on " (itoa ret) " Sheet Metal entities")) ) (T (princ "\nNo Sheet Metal entities found.")) ) (prin1) ) ; MYSMREPAIR ; Runs SMREPAIR on user selected sheet metal entities (defun C:MYSMREPAIR ( / sset ret) (cond ((SmLispGet "HasSheetMetalContext") (princ "\nSelect Sheet metal bodies to repair") (setq sset (ssget '((0 . "3DSOLID")))) (cond (sset (setq ret (SMREPAIRER sset)) (princ (strcat "\nSMREPAIR ran succesfully on " (itoa ret) " Sheet Metal entities")) ) (T (princ "\nNo Sheet Metal entities selected")) ) ) (T (princ "\nNo Sheet Metal entities present")) ) (prin1) ) (princ "\nSheet Metal Repairer loaded, Command(s): MYSMREPAIR SMREPAIRALL") (princ)
Regards,
Jason Bourhill
BricsCAD V22 Ultimate
CAD Concepts0 -
Tying to add the LISP file but getting the message "You are not allowed to upload files in this category."
Regards,
Jason Bourhill
BricsCAD V22 Ultimate
CAD Concepts0 -
Tying to add the LISP file but getting the message "You are not allowed to upload files in this category."
Regards,
Jason Bourhill
BricsCAD V22 Ultimate
CAD Concepts0 -
Tying to add the LISP file but getting the message "You are not allowed to upload files in this category."
Seems they have disabled the ability to attach .LSP files.
Download SMREPAIRER.LSP from hereRegards,
Jason Bourhill
BricsCAD V22 Ultimate
CAD Concepts0 -
Hello Jason,
Thanks for the reply this helps a lot!
I really should start learning Lisp, I have reached the limits what I can do with VBA in Bricscad.
I´m going to use your code to get me started in Lisp! Thanks again.
With kind regards,
Robert0