Jump to content

Looking for a Lisp routine


tzframpton

Recommended Posts

hi all

did anyone alter this code to allow selection of specific blocks?

ps. i am partly answering as when i click 'page2' i get a 404 forbidden error

Link to comment
Share on other sites

  • Replies 37
  • Created
  • Last Reply

Top Posters In This Topic

  • tzframpton

    6

  • designerstuart

    6

  • Lee Mac

    4

  • irneb

    3

Top Posters In This Topic

Posted Images

ps. i am partly answering as when i click 'page2' i get a 404 forbidden error

The issue is from the title of this thread, more precisely the "..." parts; this cause conflicts (at least) with IE browser. To fix it just go to address bar and remove the title part and press :

http://www.cadtutor.net/forum/showthread.php?13295-Looking-for-a-Lisp-routine..../page2

 

Hope that a moderator will fix this.

Link to comment
Share on other sites

still looking for the lisp that changes specific blocks' entities to layer0 though!
Since this thread, Autodesk incorporated the SETBYLAYER command which was not available when I was looking for this original LISP routine. Try this instead, it works really well.

 

More info: http://exchange.autodesk.com/autocad/enu/online-help/search#WS1a9193826455f5ffa23ce210c875431154102.htm

Link to comment
Share on other sites

still looking for the lisp that changes specific blocks' entities to layer0 though!
Like this?
(defun c:BlkToLay0 (/ ss n eo bLst bCol)
 (vl-load-com)
 (if (setq ss (ssget '((0 . "INSERT"))))
   (progn (repeat (setq n (sslength ss))
            (setq eo (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
            (if (not (vl-position (vla-get-EffectiveName eo) bLst))
              (setq bLst (cons (vla-get-EffectiveName eo) bLst))))
     (setq bCol (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))))
     (foreach bName bLst
       (setq eo (vla-Item bCol bName))
       (vlax-for obj eo (vl-catch-all-apply 'vla-put-Layer (list obj "0"))))))
 (princ))

Link to comment
Share on other sites

styk - that's great for setting objects 'by layer', but doesn't go the whole hog and put them on layer0.

irneb - i'm maybe doing sth wrong, but your code did nothing for me!

 

thanks all

Link to comment
Share on other sites

i'm looking to alter a bit of the former script's code so the default is my prefered choice:

 

(initget "byLayer byBlock")
     (setq atype (getkword "\nSet block contents to [byLayer/byBlock] <[color=red]byBlock[/color]>:"))
     (initget "Yes No")
     (setq ans0 (getkword "\nChange entity layers to layer0? [Yes/No] <[color=red]No[/color]>:"))

 

i want and instead. obviously i can change the words, but can someone pls tell me what bit of the code i need to alter to make it work? thanks chaps

Link to comment
Share on other sites

okay thanks lee. should have known to look on your site first!

i don't understand the first bit - but have taken the test bit, which ofc works brill like.

ta

 

still interested to learn about how to alter the code above if it's easy!

Link to comment
Share on other sites

okay thanks lee. should have known to look on your site first!

i don't understand the first bit - but have taken the test bit, which ofc works brill like.

ta

 

still interested to learn about how to alter the code above if it's easy!

 

You're welcome designerstuart.

 

Note that you needn't modify the LM:ApplytoBlockObjects function, since this is simply a wrapper function that allows you to operate on the subentities within a block definition.

 

The example program calls this function with the block collection, the block name and a function to be applied to every object within the block definition. In the example, this function merely changes the layer of every object to layer "0".

Link to comment
Share on other sites

irneb - i'm maybe doing sth wrong, but your code did nothing for me!
Could you provide a sample DWG where my code does not change the entities inside the block to layer 0? If I run it it works perfectly for me. Note, that's all it does - it leaves colour / linetype / etc. as is (though these could be added as well).

 

Or did I read your post wrong? Did you mean you want to set only certain objects inside the block to Layer 0?

 

The principle behind my code is much the same as Lee's code (aslo VVA's in post #6), though mine simply finds all blocknames from the selection then loops through each name. Lee's is a bit more of a "functional" approach, whereas VVA's & mine is more of an "imperative" approach.

Link to comment
Share on other sites

I see nothing wrong with your code Irne - perhaps designerstuart didn't do a regen to update the references. :unsure:
That's why I've asked for a sample DWG. I'd like to know where my code won't work, if such exists I'd like to learn about it.

 

You might be correct about the regen - it seems to be the most plausible reason. Thanks for checking though :thumbsup:

Link to comment
Share on other sites

Hello

 

How would that go if everything is on layer 0 only the hatching remain as it is.

Thank you

 

Hallo

 

Wie würde das gehn wenn alles auf Layer 0 nur die Schraffur soll bleiben wie sie ist.

Danke

Link to comment
Share on other sites

Hi dober,

 

To exclude Hatch Objects from the layer change, use the following program with my LM:ApplytoBlockObjects function:

 

(defun c:test ( / s )
   (if (setq s (LM:ssget "\nSelect Block: " '("_+.:E:S" ((0 . "INSERT")))))
       (LM:ApplytoBlockObjects
           (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
           (cdr (assoc 2 (entget (ssname s 0))))
          '(lambda ( obj )
               (if (not (eq "AcDbHatch" (vla-get-objectname obj)))
                   (vla-put-layer obj "0")
               )
           )
       )
   )
   (princ)
)

;; ssget  -  Lee Mac
;; A wrapper for the ssget function to permit the use of a custom selection prompt
;;
;; Arguments:
;; msg    - selection prompt
;; params - list of ssget arguments

(defun LM:ssget ( msg params / sel )
   (princ msg)
   (setvar 'nomutt 1)
   (setq sel (vl-catch-all-apply 'ssget params))
   (setvar 'nomutt 0)
   (if (and sel (not (vl-catch-all-error-p sel)))
       sel
   )
)

 

Remember to Regen to see the changes.

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