Jump to content

Find a Block and Send it to Another Layer


GregGleason

Recommended Posts

I am trying to capture items on layer “0”. I first turn all layers off except “0”, but I don’t know how to code that yet so I did it manually. I am left with one object on that layer and it is a block. My goal is to window in on an area and capture the object and sent it to another layer (in this case, the layer name is “FTG-IsoCont”). I have run the following lisp and it is not able to find the block.

 

Can someone suggest a fix?

 

; Changes selected objects to Layer from Prompt
 ; Changes selected objects to Layer FTG-IsoCont
 (defun c:SetWinToLayerFTG-IsoCont ()
 (if (setq ss1 (ssget "_C" '(0.625 1.95) '(7.15 10.45) '((0 . "FTG-IsoCont"))))
 (command "change" ss1 "" "p" "la" "FTG-IsoCont" "")
 (alert "No Objects Found")
 );; End of if
 (princ)
   )
 

Greg

Link to comment
Share on other sites

You need to use group code 8 for the layer name filter:

(setq ss1 (ssget "_C" '(0.625 1.95) '(7.15 10.45) '((0 . "insert") (8 . "FTG-IsoCont"))))

 

thank you for the code snippet.

 

But sadly it didn't work.

 

Below is an image and some attribute data of the block.

 

 

attachment.php?attachmentid=62622&cid=1&stc=1

 

 

Greg

Block.28.jpg

Link to comment
Share on other sites

You need to use group code 8 for the layer name filter:

(setq ss1 (ssget "_C" '(0.625 1.95) '(7.15 10.45) '((0 . "insert") (8 . "FTG-IsoCont"))))

 

Thanks, but the code did not work.

 

I tried running it more than once and then reloading, but it remained unmoved.

 

Greg

Link to comment
Share on other sites

A test drawing would help.

 

Can you PM me your email? I just joined the group today and I don't think I have the requisite number of posts yet to be somewhat vetted.

 

Greg

Link to comment
Share on other sites

Read your post a bit closer, if you want to select items on layer 0 using ssget, use this instead.

(setq ss1 (ssget "_C" '(0.625 1.95) '(7.15 10.45) '([b](8 . "0")[/b])))

 

No need to turn off layers .. that's part of the beauty of ssget filters.

Link to comment
Share on other sites

Read your post a bit closer, if you want to select items on layer 0 using ssget, use this instead.

(setq ss1 (ssget "_C" '(0.625 1.95) '(7.15 10.45) '([b](8 . "0")[/b])))

No need to turn off layers .. that's part of the beauty of ssget filters.

 

That one did not work either.

 

I'm trying to upload a .dwg.

 

Greg

Test.Object.DWG

Link to comment
Share on other sites

Why would you not just do find all ? You can add (cons 2 Blkname) also. For me pick a block get all the stuff like name and layer then make the selection set.

 

; Changes selected objects to Layer from Prompt
 ; Changes selected objects to Layer FTG-IsoCon

(defun c:chglay-0 ( / obj ss lay blkname)
(setq obj (vlax-ename->vla-object (car (entsel "\nPick "))))
(setq lay (vla-get-layer obj))
(if (= (vla-get-ObjectName obj) "AcDbBlockReference")
(progn
(setq blkname (vla-get-name obj))
(setq ss (ssget "x" (list (cons 0 "insert")(cons 8 lay)(cons 2 blkname))))
)
(setq ss (ssget "x" (list (cons 0 "insert")(cons 8 lay))))
)
(command "CHprop" ss "" "la" "0" "")
)

Edited by BIGAL
Link to comment
Share on other sites

Why would you not just do find all ? You can add (cons 2 Blkname) also. For me pick a block get all the stuff like name and layer then make the selection set.

 

; Changes selected objects to Layer from Prompt
 ; Changes selected objects to Layer FTG-IsoCon

(defun c:chglay-0 ( / obj ss lay blkname)
(setq obj (vlax-ename->vla-object (car (entsel "\nPick "))))
(setq lay (vla-get-layer obj))
(if (= (vla-get-ObjectName obj) "AcDbBlockReference")
(progn
(setq blkname (vla-get-name obj))
(setq ss (ssget "x" (list (cons 0 "insert")(cons 8 lay)(cons 2 blkname))))
)
(setq ss (ssget "x" (list (cons 0 "insert")(cons 8 lay))))
)
(command "CHprop" ss "" "la" "0" "")
)

 

BIGAL this does not work for me, at least as it is coded in this form. I need it to automatically capture objects in a certain sized window. The master plan is weaving this code into a larger routine, so that when the drawing is opened it is automatically cleaned up so that the user does not have to provide input.

 

Maybe just a few lines need to be revised?

 

Greg

Link to comment
Share on other sites

Here's how I'd approach this with the example provided.

(defun c:foo (/ s)
 (if (setq s (ssget "_x" '((0 . "insert") (2 . "block##") (8 . "0"))))
   (foreach x (mapcar 'cadr (ssnamex s)) (entmod (append (entget x) '((8 . "FTG-IsoCont")))))
   (print "No Objects Found...")
 )
 (princ)
)

Link to comment
Share on other sites

Here's how I'd approach this with the example provided.

(defun c:foo (/ s)
 (if (setq s (ssget "_x" '((0 . "insert") (2 . "block##") (8 . "0"))))
   (foreach x (mapcar 'cadr (ssnamex s)) (entmod (append (entget x) '((8 . "FTG-IsoCont")))))
   (print "No Objects Found...")
 )
 (princ)
)

 

Thank you ronjonp! That worked!

 

So I can learn, how is this different from the direction I went?

 

Greg

Link to comment
Share on other sites

Greg,

 

The code is not reliant on coordinates to select these objects and no command calls. Be aware that if any other blocks are on layer 0, their layer will be changed as well.

 

How did this issue arise? Your example drawing looks like it was generated by some sort of software package.

Link to comment
Share on other sites

Greg,

 

The code is not reliant on coordinates to select these objects and no command calls. Be aware that if any other blocks are on layer 0, their layer will be changed as well.

 

How did this issue arise? Your example drawing looks like it was generated by some sort of software package.

 

Yes, the drawing was generated by another software package. Some of which we can control before creation, but some has to be dealt with after the fact.

 

Greg

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