phjlc Posted April 6, 2022 Posted April 6, 2022 Hello, Just would like to ask what's the best way to do such thing as mention on the title to explain further, I want to, for example, select a Hatch and detect its layer (ex. BouGla, AtrPlx, PhiSel) and get the total planting Value of said Hatch, but each have separate nos per sqm (ex. BouGla, 3nos per sqm) In short, how can I bind the nos per sqm in a layer. Quote
exceed Posted April 6, 2022 Posted April 6, 2022 ;;; Hatched area Table sorted by Layer with the Color markers https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-table-with-hatched-areas-by-layer-name/m-p/10013361/highlight/true#M409919 Quote
phjlc Posted April 7, 2022 Author Posted April 7, 2022 Hello, Thanks for the response, but I have this code ; (defun c:Pplant () ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; CODE PLANT NAME SPC ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq Q1 '( "P/PHOE.DA" 10000 "N" )) (setq T1 '( "T/CONO.ER" 10000 "N" )) (setq T2 '( "T/CONO.SI" 10000 "N" )) (setq T3 '( "T/EUCA.OB" 10000 "N" )) (setq S1 '( "SH/CALL.CA" 0.57735 "Y" )) (setq S2 '( "SH/CLER.IN" 0.70711 "Y" )) (setq S3 '( "SH/DODO.VI" 0.57735 "Y" )) (setq S4 '( "SH/LEUC.FR" 0.57735 "Y" )) (setq S5 '( "SH/NERI.OL" 0.70711 "Y" )) (setq S6 '( "SH/THEV.PE" 0.70711 "Y" )) (setq G1 '( "GC/RUEL.BR" 0.40825 "Y" )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; ;;;; ;;;; 1 PER SQM = 1.00000 ;;;; ;;;; 2 PER SQM = 0.70711 ;;;; ;;;; 3 PER SQM = 0.57735 ;;;; ;;;; 4 PER SQM = 0.50000 ;;;; ;;;; 5 PER SQM = 0.44721 ;;;; ;;;; 6 PER SQM = 0.40825 ;;;; ;;;; 7 PER SQM = 0.37796 ;;;; ;;;; 8 PER SQM = 0.35355 ;;;; ;;;; 9 PER SQM = 0.33333 ;;;; ;;;; 10 PER SQM = 0.31623 ;;;; ;;;; 12 PER SQM = 0.28868 ;;;; ;;;; 14 PER SQM = 0.26726 ;;;; ;;;; 16 PER SQM = 0.25000 ;;;; ;;;; 18 PER SQM = 0.23570 ;;;; ;;;; 20 PER SQM = 0.22361 ;;;; ;;;; ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (vl-load-com) (setvar 'luprec 0) (SETQ SCALE 250) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; FOR SELECTING POLYLINE ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (initget 1 " Q1 T1 T2 T3 S1 S2 S3 S4 S5 S6 G1") (setq ans (getkword "\n Select Planting Code [Q1/T1/T2/T3/S1/S2/S3/S4/S5/S6/G1]")) (if (eq ans "Q1")(setq PLC Q1)) (if (eq ans "T1")(setq PLC T1)) (if (eq ans "T2")(setq PLC T2)) (if (eq ans "T3")(setq PLC T3)) (if (eq ans "T4")(setq PLC T4)) (if (eq ans "T5")(setq PLC T5)) (if (eq ans "S1")(setq PLC S1)) (if (eq ans "S2")(setq PLC S2)) (if (eq ans "S3")(setq PLC S3)) (if (eq ans "S4")(setq PLC S4)) (if (eq ans "S5")(setq PLC S5)) (if (eq ans "S6")(setq PLC S6)) (if (eq ans "G1")(setq PLC G1)) (setq PLV (list (car PLC) (cadr PLC) (caddr PLC))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; FOR SELECTING PLANT CODE ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (if (eq (caddr PLV) "Y")(progn (setq PLANTINGLINE (car (entsel "\nSelect Reference for area: "))) (setq AREA (vla-get-Area (vlax-ename->vla-object PLANTINGLINE))) (if (> (getvar 'lunits) 2) (setq AREA (/ AREA 144.)))) (setq AREA 0.0000000001)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; PLANTING FORMULA ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq PLNAME (car PLV)) (setq PLQ (+ 1(/ AREA (* (cadr PLV) (cadr PLV))))) (if (EQ "N" (caddr PLV))(SETQ PLQ (GETINT "/N HOW MANY?"))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; FOR CREATING LEADER ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq osm (getvar 'osmode)) (setvar 'osmode 0) (setq point1 (getpoint "\nselect first point")) (setq point2 (getpoint point1 "\nselect second point")) (setq point3 (getpoint point2 "\nselect last point")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; FOR SCALE OF LEADER & TEXT ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (SETQ SCALE4T (* 0.0025 SCALE)) (SETQ SCALE4C (* 0.0008 SCALE)) (if (< (car point2) (car point3)) (setq JUSTY "ML")) (if (> (Car point2) (car point3)) (setq JUSTY "MR")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; COMMANDS ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (COMMAND "_.UNDO" BE 1) (COMMAND "PLINE" point1 point2 point3 "") (COMMAND "CIRCLE" point1 SCALE4C) (COMMAND "TEXT" "J" (strcase JUSTY) point3 SCALE4T "0" (STRCAT "(" (RTOS PLQ) ")" " " (strcase PLNAME))) (COMMAND "MATCHPROP" clrmatch (ENTLAST)) (setvar 'osmode osm) (princ) ) as listed here, I have to individually type the planting code and spacing for each and type the choices with initget and getkword, is there a way to bind these presets in layer? because for different projects have a different planting. Quote
ronjonp Posted April 7, 2022 Posted April 7, 2022 (edited) One quick simplification: And make sure to localize all those variables: I'd use an association list like so to get your input: (defun c:pplant (/ ans area be clrmatch justy osm plantingline plc plname plq plv point1 point2 point3 scale scale4c scale4t values ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; CODE PLANT NAME SPC ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Association List (setq values '(("Q1" "P/PHOE.DA" 10000 "N") ("T1" "T/CONO.ER" 10000 "N") ("T2" "T/CONO.SI" 10000 "N") ("T3" "T/EUCA.OB" 10000 "N") ("S1" "SH/CALL.CA" 0.57735 "Y") ("S2" "SH/CLER.IN" 0.70711 "Y") ("S3" "SH/DODO.VI" 0.57735 "Y") ("S4" "SH/LEUC.FR" 0.57735 "Y") ("S5" "SH/NERI.OL" 0.70711 "Y") ("S6" "SH/THEV.PE" 0.70711 "Y") ("G1" "GC/RUEL.BR" 0.40825 "Y") ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; ;;;; ;;;; 1 PER SQM = 1.00000 ;;;; ;;;; 2 PER SQM = 0.70711 ;;;; ;;;; 3 PER SQM = 0.57735 ;;;; ;;;; 4 PER SQM = 0.50000 ;;;; ;;;; 5 PER SQM = 0.44721 ;;;; ;;;; 6 PER SQM = 0.40825 ;;;; ;;;; 7 PER SQM = 0.37796 ;;;; ;;;; 8 PER SQM = 0.35355 ;;;; ;;;; 9 PER SQM = 0.33333 ;;;; ;;;; 10 PER SQM = 0.31623 ;;;; ;;;; 12 PER SQM = 0.28868 ;;;; ;;;; 14 PER SQM = 0.26726 ;;;; ;;;; 16 PER SQM = 0.25000 ;;;; ;;;; 18 PER SQM = 0.23570 ;;;; ;;;; 20 PER SQM = 0.22361 ;;;; ;;;; ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (vl-load-com) (setvar 'luprec 0) (setq scale 250) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; FOR SELECTING POLYLINE ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (initget 1 "Q1 T1 T2 T3 S1 S2 S3 S4 S5 S6 G1") (setq ans (getkword "\n Select Planting Code [Q1/T1/T2/T3/S1/S2/S3/S4/S5/S6/G1]")) (setq plc (cdr (assoc ans values))) (setq plv plc) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; FOR SELECTING PLANT CODE ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (if (eq (caddr plv) "Y") ;; RJP - add IF (if (setq plantingline (car (entsel "\nSelect Reference for area: "))) (progn (setq area (vla-get-area (vlax-ename->vla-object plantingline))) (if (> (getvar 'lunits) 2) (setq area (/ area 144.)) ) ) ) (setq area 0.0000000001) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; PLANTING FORMULA ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq plname (car plv)) (setq plq (+ 1 (/ area (* (cadr plv) (cadr plv))))) (if (eq "N" (caddr plv)) (setq plq (getint "/N HOW MANY?")) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; FOR CREATING LEADER ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq osm (getvar 'osmode)) (setvar 'osmode 0) (setq point1 (getpoint "\nselect first point")) (setq point2 (getpoint point1 "\nselect second point")) (setq point3 (getpoint point2 "\nselect last point")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; FOR SCALE OF LEADER & TEXT ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq scale4t (* 0.0025 scale)) (setq scale4c (* 0.0008 scale)) (if (< (car point2) (car point3)) (setq justy "ML") ) (if (> (car point2) (car point3)) (setq justy "MR") ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; COMMANDS ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (command "_.UNDO" be 1) (command "PLINE" point1 point2 point3 "") (command "CIRCLE" point1 scale4c) (command "TEXT" "J" (strcase justy) point3 scale4t "0" (strcat "(" (rtos plq) ")" " " (strcase plname)) ) (command "MATCHPROP" clrmatch (entlast)) (setvar 'osmode osm) (princ) ) Edited April 7, 2022 by ronjonp Quote
phjlc Posted April 12, 2022 Author Posted April 12, 2022 Hi ronjonp Thank you for the reply, I will sure look into association list, Just want to ask why do i have to localize all those variables? also I've read about substr and came up with this; (if (eq UNIV-SCALE nil) (Alert "PLEASE SET UP SCALE FIRST") (progn ;checking if scale is set (setq eL (vlax-ename->vla-object (car (entsel "alin ba"))) ;getting layer cL (vlax-get-property eL 'Layer)) ;convert layer to string (if (eq (strlen cl) 22) (progn ;checking if layer is correct (setq PL-C (substr cL 1 (- (strlen cL) 15)) ;Yield Planting Code PL-T (substr cL 9 (- (strlen cL) 20)) ;Yield Planting Type PL-S (read (substr cL 12 (- (strlen cL) 18))) ;Yield Planting Spacing or nos per SQM PL-UN (substr cL 17 (- (strlen cL) 19)) ;identifies if computation is by spacing or nos per sqm UN (substr cL 21 (- (strlen cL) 0)) ;unit of said drawing AREA (vla-get-Area eL) ;getting area of selected hatch asd-p1 (getpoint "\n 1st point") ;first point for leader asd-p2 (getpoint asd-p1 "\n 2nd point") ;second point for leader asd-p3 (getpoint asd-p2 "\n 3rd point") ;third point for leader asd-p3m (list (car asd-p3)(+ (cadr asd-p3) 12) (caddr asd-p3)) ;for mirror block PL-C-F (strcase (strcat "" PL-T"/"PL-C)) ;combinding code and pl type ) with a layer "BOU GLA SH 0006 NPS MM", I extract the needed information by dissecting the layer, so needless to say I resolve it but still thankyou for the reply kind sirs. Quote
exceed Posted April 12, 2022 Posted April 12, 2022 18 minutes ago, phjlc said: why do i have to localize all those variables about variable localization, see this link. http://www.lee-mac.com/localising.html It may work normally on the first run, but after the second run, the old value may remain and an error may occur. Setting the initial value at the beginning of every defun doesn't cause a big problem, but there is the following problem. If other Lisp is loaded and used, unexpected results may occur if the Lisp and variable names overlap. These problems can be solved by simply writing (defun c:test ( / variablea variableb variablec )~~ Quote
pBe Posted April 13, 2022 Posted April 13, 2022 (edited) On 4/12/2022 at 9:04 AM, phjlc said: with a layer "BOU GLA SH 0006 NPS MM", I extract the needed information by dissecting the layer, so needless to say I resolve it but still thankyou for the reply kind sirs. Now you opted to use layer names as the source for the plant data? I think you're better off using an external source file, that way you can "update" the string when the PL-S data changes. of course that will require another code. Edited April 13, 2022 by pBe Quote
phjlc Posted April 13, 2022 Author Posted April 13, 2022 1 hour ago, pBe said: Now you opted to use layer names as the source for the plant data? I think you're better off using an external source file, that way you can "update" the string when the PL-S data changes. of course that will require another code. I see your point Sir pBe, but where Im getting at is for others to use my code without the knowledge of lisp, and I think doing it this way is much easier to explain to my work mates, I mean if they can create layer and edit its name, they can use it easily enough. Quote
pBe Posted April 13, 2022 Posted April 13, 2022 56 minutes ago, phjlc said: .. I mean if they can create layer and edit its name, they can use it easily enough. Fair enough 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.