Jump to content

Check circle on layer


ahyin

Recommended Posts

Dear all,

I'm writing a lisp,anybody can help me ?

I have many layers for user to select by dcl dialog box, after selected the items (may be more than one) by user,I will turn on this layer and check have circle objects in this layer or not. Because of more than 50 items.If I use if then else to check each flag will make my lisp program become very long. Any other good method to do that ?

 

(if (= item1 1)
(progn
(setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
    (setq theLayers (vla-get-layers acadDocument))
    (vlax-for item theLayers (vlax-put-property item "LayerON" ':vlax-false)) 
(command "-layer" "On" (vlax-get-property item1-layer 'Name) "")
   (setq sset (ssget "_a" (LIST '(0 . "CIRCLE") (8 . item1-layer) (cons 410 (getvar "CTAB")))))
)
)
(if (= item2 1)
(progn
(setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
    (setq theLayers (vla-get-layers acadDocument))
    (vlax-for item theLayers (vlax-put-property item "LayerON" ':vlax-false)) 
(command "-layer" "On" (vlax-get-property item2-layer 'Name) "")
   (setq sset (ssget "_a" (LIST '(0 . "CIRCLE") (8 . item2-layer) (cons 410 (getvar "CTAB")))))
)
)

.

.

.

.

.

Edited by Tiger
added code-tags
Link to comment
Share on other sites

Take a look to FOREACH function - this means that you will have to store those layer names in a list.

 

(foreach Item '(1 2 3 4 5)
(print Item)
)

 

 

Regards,

Link to comment
Share on other sites

thanks ! I will try use to this function to complete my lisp

 

Take a look to FOREACH function - this means that you will have to store those layer names in a list.

 

(foreach Item '(1 2 3 4 5)
(print Item)
)

 

 

Regards,

Link to comment
Share on other sites

No problem!

 

Also, to deal with repetitive codes may be a good idea to write a function with parameters for that part and call it instead of having the same piece of code in more than one place. This will ensure a more compact code and help you to maintain it – that it, make changes in only one places.

 

In this case your code excerpt will become:

 

(defun [color=Blue]CirclesInLayer[/color]( [color=DarkGreen]theLayer[/color] )
(setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
    (setq theLayers (vla-get-layers acadDocument))
    (vlax-for item theLayers (vlax-put-property item "LayerON" ':vlax-false))
(command "-layer" "On" (vlax-get-property theLayer 'Name) "")
   (setq sset (ssget "_a" (LIST '(0 . "CIRCLE") (8 . theLayer) (cons 410 (getvar "CTAB")))))
)
)

(if (= item1 1)
([color=Blue]CirclesInLayer[/color] [color=DarkGreen]item1-layer[/color])
)

(if (= item2 1)
([color=Blue]CirclesInLayer[/color] [color=DarkGreen]item2-layer[/color])
)

Regards,

Link to comment
Share on other sites

Thank you very much, this would be really great !

No problem!

 

Also, to deal with repetitive codes may be a good idea to write a function with parameters for that part and call it instead of having the same piece of code in more than one place. This will ensure a more compact code and help you to maintain it – that it, make changes in only one places.

 

In this case your code excerpt will become:

 

(defun [color=Blue]CirclesInLayer[/color]( [color=DarkGreen]theLayer[/color] )
(setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
(setq theLayers (vla-get-layers acadDocument))
(vlax-for item theLayers (vlax-put-property item "LayerON" ':vlax-false))
(command "-layer" "On" (vlax-get-property theLayer 'Name) "")
(setq sset (ssget "_a" (LIST '(0 . "CIRCLE") (8 . theLayer) (cons 410 (getvar "CTAB")))))
)
)

(if (= item1 1)
([color=Blue]CirclesInLayer[/color] [color=DarkGreen]item1-layer[/color])
)

(if (= item2 1)
([color=Blue]CirclesInLayer[/color] [color=DarkGreen]item2-layer[/color])
)

Regards,

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