Autodesk Community, Autodesk Forums, Autodesk Forum
forums.autodesk.com.web.brid.gy
Autodesk Community, Autodesk Forums, Autodesk Forum
@forums.autodesk.com.web.brid.gy
Find answers, share expertise, and connect with your peers.

[bridged from https://forums.autodesk.com/ on the web: https://fed.brid.gy/web/forums.autodesk.com ]
Efficient Coding, suppressing and unsuppressing features with parameters and rules
Is there a more efficient way (processing wise, ease of writing wise, ease of understanding wise) to write this code? 'Reinforcement Kerf Count Left Feature.IsActive("Reinforcement Kerf L 1") = False Feature.IsActive("Reinforcement Kerf L 2") = False Feature.IsActive("Reinforcement Kerf L 3") = False Feature.IsActive("Reinforcement Kerf L 4") = False Feature.IsActive("Reinforcement Kerf L 5") = False Feature.IsActive("Reinforcement Kerf L 6") = False If ReinforcementKerfCountL = 1 Then Feature.IsActive("Reinforcement Kerf L 1") = True Else If ReinforcementKerfCountL = 2 Then Feature.IsActive("Reinforcement Kerf L 1") = True Feature.IsActive("Reinforcement Kerf L 2") = True Else If ReinforcementKerfCountL = 3 Then Feature.IsActive("Reinforcement Kerf L 1") = True Feature.IsActive("Reinforcement Kerf L 2") = True Feature.IsActive("Reinforcement Kerf L 3") = True Else If ReinforcementKerfCountL = 4 Then Feature.IsActive("Reinforcement Kerf L 1") = True Feature.IsActive("Reinforcement Kerf L 2") = True Feature.IsActive("Reinforcement Kerf L 3") = True Feature.IsActive("Reinforcement Kerf L 4") = True Else If ReinforcementKerfCountL = 5 Then Feature.IsActive("Reinforcement Kerf L 1") = True Feature.IsActive("Reinforcement Kerf L 2") = True Feature.IsActive("Reinforcement Kerf L 3") = True Feature.IsActive("Reinforcement Kerf L 4") = True Feature.IsActive("Reinforcement Kerf L 5") = True Else If ReinforcementKerfCountL = 6 Then Feature.IsActive("Reinforcement Kerf L 1") = True Feature.IsActive("Reinforcement Kerf L 2") = True Feature.IsActive("Reinforcement Kerf L 3") = True Feature.IsActive("Reinforcement Kerf L 4") = True Feature.IsActive("Reinforcement Kerf L 5") = True Feature.IsActive("Reinforcement Kerf L 6") = TrueEnd If "Reinforcement Kerf '_'" refers to an extrude/cut feature on my part. I have 6 separate ones at different spacing on the left side of the component Certain model states need none, some need 3, some need 6, etc. So instead of manually suppressing and un-suppressing them, I made a multi-value parameter and rule to suppress and unsuppress one or multiple features at once. On a form I use the option with a radio group: ReinforcementKerfCountL ~ Reinforcement Kerf Count Left : "0"  ,  "1"  ,  "2"  ,  "3"  ,  "4"  ,  "5"  ,  "6" When I click a button, it will suppress and unsuppress the 6 cut/extrude features accordingly. Button "0" suppresses all of them Button "4" suppresses feature 5 & 6 while unsuppressing features 1-4 so I have 4 cuts on my part Same for the other buttons And I notice when I click different buttons the features flash on and off before finally staying steady on or off once it's worked through the code, like it's in a slight loop as it runs the rule. I'm not the best cod writer at all. So I'm curious if there's a better way of writing what I have.
forums.autodesk.com
December 16, 2025 at 11:56 PM
Trying to extract leader mtext contents as part of data-csv export
Hello, I am trying to extract data to a csv from a fairly ugly drawing. I have gotten most of it but there remains a large number of mleaders pointing to most of the blocks involved, containing the customer number for the poles the blocks represent. I've got the mleader selection down, but I have no idea what kind of property/dxf code/whatever will identify the mtext contents. List and Dump were not illuminating. Code is below: (defun c:PPL ( / PlGrp LdrGrp DstCSV SnpHld EchHld PlNmbr PlLst LdrLst Nrthng Estng Elv Lctn RwLst) (vl-load-com) (command _attdia 0) ; turnoff attdia (setq SnpHld (getvar 'osmode)) ; records current snap settings (setvar 'osmode 0) ; turns off snaps (setq EchHld (getvar 'cmdecho)) (setvar 'cmdecho 0) (defun LM:ss->ent ( ss / i m ) (if ss (repeat (setq i (sslength ss)) (setq m (cons (ssname ss (setq i (1- i))) m)) ) ) ) (defun SelectBlocks ( / ) (setq PlGrp (ssget "_X" (list '(0 . "INSERT") (cons 2 "PP_ANNO")))) ;;selecting all PP_ANNO blocks (if (eq PlGrp nil) (princ) (setq PlLst (LM:ss->ent PlGrp)) ) ) (defun SelectLeaders ( / ) (setq LdrGrp (ssget "_X" '((0 . "MULTILEADER")))) (if (eq LdrGrp nil) (setq LdrLst nil) (setq LdrLst (LM:ss->ent LdrGrp)) ) ) (defun Extract (c / ) (setq Nrthng (getpropertyvalue c "Position/Y")) (setq Estng (getpropertyvalue c "Position/X")) (setq Elv (getpropertyvalue c "Position/Z")) (setq Lctn (list (rtos Nrthng 2 3) (rtos Estng 2 3) (rtos Elv 2 3 ))) ) (defun Writefile (FlNm lst / f x z) (cond ((and (eq 'str (type FlNm)) (setq z (open FlNm "w"))) ; While the file name is a string and the ; file is open for writing then: (foreach x lst (if (= 'list (type x)) ; if x is a list then: (write-line (apply 'strcat (mapcar '(lambda (z) (strcat (vl-princ-to-string z) ",")) x)) z ) ; end true (vl-princ-to-string x) ; end false ) ) ; end foreach (close z) ; close file FlNm ) ; end "and" ) ; end cond ) (defun core (/ a b Hld Hdr MLNrth MLEst MLElv) (SelectBlocks) (SelectLeaders) ;; was the primary selection method, now only verifying leaders exist to (if (eq LdrLst nil) ;; determine extract columns (progn (setq Hdr (list "Northing" "Easting" "Elev")) ;; Files without leaders leave out the ID column (setq RwLst (cons Hdr RwLst)) ;; setting headers (foreach a PlLst (progn (Extract a) (setq RwLst (cons Lctn RwLst)) ;; constructing list of lists for writefile ) ) ) (progn (setq Hdr (list "Northing" "Easting" "Elev" "PoleID")) ;; files that have at least one leader (setq RwLst (cons Hdr RwLst)) ;; add the PoleID column (Extract a) ;; for each holder block (setq NEBx (list (+ Nrthng 0.15) (+ Estng 0.15))) (setq SWBx (list (- Nrthng 0.15) (- Estng 0.15))) (setq LdrChk (ssget "_C" NEBx SWBx '((0 . "MULTILEADER")))) ;; select nearby multileaders (if (eq LdrChk nil) ;; If no ID on this block insert dash (setq PlID "-") (progn ;; ID present extract value of pole ID (setq PlID ( insert mtext contents here)) (setq Lctn (reverse Lctn)) (setq Lctn (cons PlID Lctn)) ;; adding Pole ID (setq Lctn (reverse Lctn)) (setq RwLst (cons Lctn RwLst)) ;; adding line to RwLst ) ) ) ) (setq RwLst (reverse RwLst)) (princ (WriteFile (strcat (getvar 'dwgprefix) "PoleSheet.csv") RwLst)) ) (core) (setvar 'osmode SnpHld) (if (eq EchHld nil) (setvar 'cmdecho 0) (setvar 'cmdecho EchHld) ) ) Line 88 is the one I need help with. Thanks for any help Gorra
forums.autodesk.com
December 16, 2025 at 9:56 PM