Jump to content

Help to fix this


gS7

Recommended Posts

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 

Link to comment
Share on other sites

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 by dlanorh
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 by BIGAL
Link to comment
Share on other sites

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)
)

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...