Jump to content

Combine two LISPs to one


verb222

Recommended Posts

Hi, I need help. I would like to make new LISP from existing two that I found.

Fist one delivers selection set (according to attribute value) that should be used by second one (changing layer of selected objects).

I think it is trivial, but I don't know how to do it. I gave it some time on google, but learned nothing.

 

I wolud like not to select anything during execution.

I'll change layer names on my-own later in code (this is first step od my idea of global layer change for lots of same attributes (with different specific attribute value).

 

 

1.

(defun c:attselect ( / ss2 ss tag val n na)

(setq ss2 (ssadd))
(sssetfirst nil nil)
(princ "\nSelect blocks containing attributes.")
(if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
   (progn
    (setq tag "COLOR"
          val "OR (1)"
    );setq
    (if (equal tag "")
        (setq tag "*")
    );if
    (if (equal val "")
        (setq val "*")
    );if
    (setq n 0)
    (repeat (sslength ss)
    (setq na (ssname ss n))
    (if (sample_att_match na tag val)
        (setq ss2 (ssadd na ss2))
    );if
    (setq n (+ n 1));setq
    );repeat
    (if (equal (getvar "cmdnames")  "")
        (sssetfirst ss2 ss2)
        (command ss2)
    );if
   );progn then
);if
(princ)
);defun c:attselect

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun sample_att_match ( na tag val / e1 a b flag)
(while (and (setq na (entnext na))
            (setq e1 (entget na)) 
            (not (equal (cdr (assoc 0 e1)) "SEQEND"))
            (not flag)
       );and
  (if (equal (cdr (assoc 0 e1)) "ATTRIB")
      (progn
       (setq a (cdr (assoc 2 e1)) ;2 is tag
             b (cdr (assoc 1 e1)) ;1 is value 
       );setq
       (if (and a
                (wcmatch a tag)
                b
                (wcmatch b val)
           );and
           (setq flag T);then jump out of the loop
       );if
      );progn then attrib
  );if
 );while
flag
);defun sample_att_match

(princ "\nType ATTSELECT to run")
(princ)

 

I made change to original code (tag "COLOR", val "OR (1)") that I found somewhere.

 

2.

; Changes selected objects to Layer PL1
(defun c:setpl1 ()
 (tolayer
   (ssget "_:L") ;;selection
   "PL1"         ;;Layer
   )
 (princ)
)
(defun tolayer ( ss lay / i e )
 ;;; ss - pickset
 ;;; lay -layer name
 (repeat (setq i (sslength ss))
   (entmod
     (subst
       (cons 8 lay)
       (assoc 8 (entget (setq e (ssname ss (setq i (1- i))))))
       (entget e)
       )
     )
   )
 )

 

This code is found on this forum: http://www.cadtutor.net/forum/showthread.php?67438-LISP-to-move-selected-objects-to-a-specified-layer

published by VVA.

Thanx him, and creator of first code (unknown).

Thanx to the future "combiner" :)

Link to comment
Share on other sites

a couple of changes

 

not tested
(defun c:attselect ( / ss2 tag val n na) ss has been removed so makes it a global variable

ignore setpl1

(defun c:test ()
(c:attselect)
(setq lay "PL1")
(defun tolayer ( ss lay / i e ) ;ignore setpl1
)

Edited by SLW210
fixed code tag
Link to comment
Share on other sites

Hmm.. I've haven't been successful implementing your's advises. I have lack of knowledge. I've been trying, adding, permutating, experimenting, I've been reading AlfaLISP, JeffryLISP... Couldn't find topic related to "combining". I don't understand general logic of executing different functions in one code (in one *.lsp).

Please, can you do it for me, I'll try to gain knowledge from it, not just use it :)

Link to comment
Share on other sites

Hi, I decided to read a book first. I did learned something, lots of things are more clear now... and I made code work. Please keep in mind that I am beginner in LISP, for now I am just happy when code works :).

 

It seems to me that variable ss2 should be global, because I need that selection set in tolayer function. This way it works.

 

I need further help, every comment is helpful. I feel like student again (cannot get professor consultation without personel preparation on topic :)).

I attached Example1.dwg to easier test.

Please, take look at comments in code.

 

Here's the code:

 

;|combining attselect and layer change.
c:test- it works!
- at the end should do this: select all blocks in drawing, filter it by attribute value "OR (1)", change layer of those to PURPLE
- main command that combines two of those:
	c:attselect - selects all blocks in layer GREEN with attribute value "OR (1)"
	c:tolay - it changes selection layer to PURPLE

idea1: I wish that I dont need to select manualy whole drawing with mouse. I wish LISP do it without me.
idea2: Later... :-)	|;


;final combining command
(defun c:test ()
(c:attselect)
(c:tolay)
)


;makes selection (only blocks within layer GREEN)
(defun c:attselect ( / ss tag val n na)

(setq ss2 (ssget "all" '((8 . "GREEN")(0 . "INSERT"))))	
;|
comment for line above
this is original line in original command: (setq ss2 (ssadd))  
I'm trying to make this selection automatic (without mouse input of selecting all
I don't know how!!!
|;

(sssetfirst nil nil)
(princ "\nSelect blocks containing attributes.")
(if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
   (progn
    (setq tag "COLOR"
          val "OR (1)"
    );setq
    (if (equal tag "")
        (setq tag "*")
    );if
    (if (equal val "")
        (setq val "*")
    );if
    (setq n 0)
    (repeat (sslength ss)
    (setq na (ssname ss n))
    (if (sample_att_match na tag val)
        (setq ss2 (ssadd na ss2))
    );if
    (setq n (+ n 1));setq
    );repeat
    (if (equal (getvar "cmdnames")  "")
        (sssetfirst ss2 ss2)
        (command ss2)
    );if
   );progn then
);if
(princ)
);defun c:attselect

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun sample_att_match ( na tag val / e1 a b flag)
(while (and (setq na (entnext na))
            (setq e1 (entget na)) 
            (not (equal (cdr (assoc 0 e1)) "SEQEND"))
            (not flag)
       );and
  (if (equal (cdr (assoc 0 e1)) "ATTRIB")
      (progn
       (setq a (cdr (assoc 2 e1)) ;2 is tag
             b (cdr (assoc 1 e1)) ;1 is value 
       );setq
       (if (and a
                (wcmatch a tag)
                b
                (wcmatch b val)
           );and
           (setq flag T);then jump out of the loop
       );if
      );progn then attrib
  );if
 );while
flag
);defun sample_att_match

(princ "\nType ATTSELECT to run")
(princ)




; changes layer of selection provided by attselect
(defun c:tolay ()
 (command "_.chprop" (eval ss2) "" "_layer" "PURPLE" "")
)

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