gS7 Posted February 16, 2020 Posted February 16, 2020 Hi Guys, I need a Help here i have created a autolisp for insert Blocks , in this i am showing invalid layers for user I.e block not available for that layers. But my problems is if same layer found more then one it will repeat for all same layers i don't want to show error for every same layers. Please help me (defun c:parkingblock(/ addblock ss acaddocument space i snm lnm pos) (vl-load-com) (defun addblock (sp pos nm lname en / b) (setq b (vla-insertblock sp pos nm 0.1 0.1 0.1 0.0)) (vla-put-layer b lname) (vla-delete en) ) (if (setq ss (ssget '((0 . "POINT")))) (progn (setq acadDocument (vla-get-activedocument (vlax-get-acad-object))) (setq space (vla-get-modelspace acadDocument)) (repeat (setq i (sslength ss)) (setq snm (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (setq lnm (vlax-get snm 'layer)) (setq pos (vla-get-Coordinates snm)) (cond ((= lnm "P_SEM_P") (addblock space pos "937" "P_SEM_P" snm)) ((= lnm "P_ILL_P") (addblock space pos "950" "P_ILL_P" snm)) ((= lnm "ALB_P") (addblock space pos "968" "ALB_P" snm)) ((= lnm "P_TEL_P") (addblock space pos "980" "P_TEL_P" snm)) ((= lnm "ZSD_P") (addblock space pos "953" "ZSD_P" snm)) ((= lnm "DIS_SOST") (addblock space pos "926" "DIS_SOST" snm)) (t (princ (strcat "\nBlock not found for Layer: " lnm)));; Problem ) ) ) ) (princ)) Regards, Ganesh Quote
dlanorh Posted February 16, 2020 Posted February 16, 2020 (edited) 53 minutes ago, gS7 said: Hi Guys, I need a Help here i have created a autolisp for insert Blocks , in this i am showing invalid layers for user I.e block not available for that layers. But my problems is if same layer found more then one it will repeat for all same layers i don't want to show error for every same layers. Please help me (defun c:parkingblock(/ addblock ss acaddocument space i snm lnm pos) (vl-load-com) (defun addblock (sp pos nm lname en / b) (setq b (vla-insertblock sp pos nm 0.1 0.1 0.1 0.0)) (vla-put-layer b lname) (vla-delete en) ) (if (setq ss (ssget '((0 . "POINT")))) (progn (setq acadDocument (vla-get-activedocument (vlax-get-acad-object))) (setq space (vla-get-modelspace acadDocument)) (repeat (setq i (sslength ss)) (setq snm (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (setq lnm (vlax-get snm 'layer)) (setq pos (vla-get-Coordinates snm)) (cond ((= lnm "P_SEM_P") (addblock space pos "937" "P_SEM_P" snm)) ((= lnm "P_ILL_P") (addblock space pos "950" "P_ILL_P" snm)) ((= lnm "ALB_P") (addblock space pos "968" "ALB_P" snm)) ((= lnm "P_TEL_P") (addblock space pos "980" "P_TEL_P" snm)) ((= lnm "ZSD_P") (addblock space pos "953" "ZSD_P" snm)) ((= lnm "DIS_SOST") (addblock space pos "926" "DIS_SOST" snm)) (t (princ (strcat "\nBlock not found for Layer: " lnm)));; Problem ) ) ) ) (princ)) Regards, Ganesh Perhaps your layer names are not all upper case! When using the (=) function "Defpoints" does not = "DEFPOINTS" so you should test like this (= (strcase lnm) "P_SEM_P") ;or change this (setq lnm (vlax-get snm 'layer)) ;; to (setq lnm (strcase (vlax-get snm 'layer))) Edited February 16, 2020 by dlanorh Quote
gS7 Posted February 17, 2020 Author Posted February 17, 2020 Hi Dlanorh , I think you did not get my point. It will repeat same layer names like this. If same layer for more then one i want to show them only one time to user Example : Block not found for Layer: P_SEG_P Block not found for Layer: M_SEG_P Block not found for Layer: COL_EL Block not found for Layer: M_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: M_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: M_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: M_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: RBPA_A Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: M_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: M_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: M_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: COL_EL Block not found for Layer: COL_EL Block not found for Layer: COL_EL Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: P_SEG_P Block not found for Layer: M_SEG_P Quote
BIGAL Posted February 17, 2020 Posted February 17, 2020 (edited) You need some sort of flag list ("P_SEG_P" "yes") so if its yes don't display else change ("P_SEG_P" "No") to yes. You will need to make the list before hand of all the corresponding layers make it a defun saves lots of code in main routine and you can test separately as it will need a repeat for the length of the list. Plus a double nth or car & cadr (("P_SEG_P" "No")("M_SEG_P" "No")(COL_…….) (t (princ (strcat "\nBlock not found for Layer: " lnm)));; Problem Edited February 17, 2020 by BIGAL Quote
Roy_043 Posted February 17, 2020 Posted February 17, 2020 Untested (no sample DWG) but something like this should work: (defun c:parkingblock(/ addblock ss acaddocument space i snm lnm pos missingLyrLst) (vl-load-com) (defun addblock (sp pos nm lname en / b) (setq b (vla-insertblock sp pos nm 0.1 0.1 0.1 0.0)) (vla-put-layer b lname) (vla-delete en) ) (if (setq ss (ssget '((0 . "POINT")))) (progn (setq acadDocument (vla-get-activedocument (vlax-get-acad-object))) (setq space (vla-get-modelspace acadDocument)) (repeat (setq i (sslength ss)) (setq snm (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (setq lnm (vlax-get snm 'layer)) (setq pos (vla-get-Coordinates snm)) (cond ((vl-position lnm missingLyrLst) nil ) ((= lnm "P_SEM_P") (addblock space pos "937" "P_SEM_P" snm) ) ((= lnm "P_ILL_P") (addblock space pos "950" "P_ILL_P" snm) ) ((= lnm "ALB_P") (addblock space pos "968" "ALB_P" snm) ) ((= lnm "P_TEL_P") (addblock space pos "980" "P_TEL_P" snm) ) ((= lnm "ZSD_P") (addblock space pos "953" "ZSD_P" snm) ) ((= lnm "DIS_SOST") (addblock space pos "926" "DIS_SOST" snm) ) (t (setq missingLyrLst (cons lnm missingLyrLst)) (princ (strcat "\nBlock not found for Layer: " lnm)) ) ) ) ) ) (princ) ) Quote
gS7 Posted February 17, 2020 Author Posted February 17, 2020 Thank you Bigal for your suggestion . and Roy_043 It is working like charm thank you for your codes. 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.