Jump to content

Recommended Posts

Posted

Dear all,

 

I would like to make lisp with dialog box and let user to select which layer want to scale the circle by 2 times. I don't know how to write the code able to store the selected items,and that repeat the command. Anyone can teach me how to complete the code ? Thanks !

(defun sc2 ()
(if 
(= item1 1) (setq sset (ssget "x"  '(8 . "layer1" ) (0 . "CIRCLE")(cons 410 (getvar "CTAB"))))
(= item2 1) (setq sset (ssget "x"  '(8 . "layer2" ) (0 . "CIRCLE")(cons 410 (getvar "CTAB"))))
(= item3 1) (setq sset (ssget "x"  '(8 . "layer3" ) (0 . "CIRCLE")(cons 410 (getvar "CTAB"))))
(setq sset (vlax-safearray-list sset))
);if 
(repeat sset 
(command "scale" ssget 2 "")
     
);repeat
);defun

Posted (edited)

Maybe something like this ... :)

 

(defun sc2 ()
(cond
     ((= item1 1) (setq sset (ssget "x"  (list '(8 . "layer1" ) '(0 . "CIRCLE")(cons 410 (getvar "CTAB"))))))
     ((= item2 1) (setq sset (ssget "x"  (list '(8 . "layer2" ) '(0 . "CIRCLE")(cons 410 (getvar "CTAB"))))))
     ((= item3 1) (setq sset (ssget "x"  (list '(8 . "layer3" ) '(0 . "CIRCLE")(cons 410 (getvar "CTAB"))))))
     )
 (if sset
   (repeat (setq i (sslength sset))
     (setq sn (ssname sset (setq i (1- i))))
     (entmod (subst (cons 40 (* (cdr (assoc 40 (setq e (entget sn)))) 4.)) (assoc 40 e) e)) 
   )
 )
(princ)
)

Edited by Tharwat
Replaced Scale command with entmod function
Posted
(defun c:test (/ ss ent)
 (setq ss (ssget "_X"
   (list '(0 . "CIRCLE") (cons 410 (getvar "CTAB")))
   )
 )
 (repeat (sslength ss)
   (setq ent (ssname ss 0))
   (if (member (strcase (cdr (assoc 8 (entget ent))))
 '("LAYER1" "LAYER2" "LAYER3")
)
     (command "_scale"
       ent
       ""
       "_non"
       (cdr (assoc 10 (entget ent)))
       "2"
     )
   )
   (ssdel ent ss)
 )
)

Posted

Thanks for quick response, if I selected more than one items (i.e. item1 , item3) and the layer1 and layer3 more than one circle. How to make this lisp can repeat it ?

 

 

Maybe something like this ... :)

 

(defun sc2 ()
(cond
((= item1 1) (setq sset (ssget "x" (list '(8 . "layer1" ) '(0 . "CIRCLE")(cons 410 (getvar "CTAB"))))))
((= item2 1) (setq sset (ssget "x" (list '(8 . "layer2" ) '(0 . "CIRCLE")(cons 410 (getvar "CTAB"))))))
((= item3 1) (setq sset (ssget "x" (list '(8 . "layer3" ) '(0 . "CIRCLE")(cons 410 (getvar "CTAB"))))))
)
(if sset
(repeat (setq i (sslength sset))
(setq sn (ssname sset (setq i (1- i))))
(command "_.scale" sn "" (cdr (assoc 10 (entget sn))) 2. "")
)
)
(princ)
)

Posted

Thanks for quick response, this lisp will scale all circle by 2 times. Because I will select which layer I wanted to scale 2 times by the dialog box selection interface.

 

(defun c:test (/ ss ent)
 (setq ss (ssget "_X"
   (list '(0 . "CIRCLE") (cons 410 (getvar "CTAB")))
   )
 )
 (repeat (sslength ss)
   (setq ent (ssname ss 0))
   (if (member (strcase (cdr (assoc 8 (entget ent))))
 '("LAYER1" "LAYER2" "LAYER3")
)
     (command "_scale"
       ent
       ""
       "_non"
       (cdr (assoc 10 (entget ent)))
       "2"
     )
   )
   (ssdel ent ss)
 )
)

Posted
Thanks for quick response, if I selected morethan one items (i.e. item1 , item3) and the layer1 and layer3 more than one circle. How to make this lisp can repeat it ?

 

I updated my code with entmod which is better and faster .:)

 

In regard to your question , I did not get it , could you bring your codes or an example ?

Posted (edited)
Thanks for quick response, this lisp will scale all circle by 2 times. Because I will select which layer I wanted to scale 2 times by the dialog box selection interface.

 

Well then. with the resulting value from your dialog function assign the layer names on a list, for example form your lsit box you select "LAYER1" and "LAYER3". construct a list with this two names i.e ("LAYER1" "LAYER3") and pass that as an argument t this sub.

 

(defun [b][color=blue]ScleCir  (lst[/color][/b] / ss ent)
 (setq ss (ssget "_X"
   (list '(0 . "CIRCLE") (cons 410 (getvar "CTAB")))
   )
 )
 (repeat (sslength ss)
   (setq ent (ssname ss 0))
   (if (member (strcase (cdr (assoc 8 (entget ent))))
[b][color=blue] lst[/color][/b]
)
     [b][color=blue](entmod[/color][/b]
[b][color=blue] (subst (cons 40 (* (cdr (assoc 40 (setq e (entget ent)))) 2))[/color][/b]
[b][color=blue] (assoc 40 e)[/color][/b]
[b][color=blue] e[/color][/b]
[b][color=blue] )[/color][/b]
)
   )
   (ssdel ent ss)
 )
)

 

or

 

(defun [color=blue]ScleCir (lst[/color] / ss ent)
 (setq
   ss (ssget
 "_X"
 (list
   '(0 . "CIRCLE")
   (cons 410 (getvar "CTAB"))
   [b][color=blue](cons
     2
     (apply 'strcat (mapcar '(lambda (j) (strcat "," j)) lst))
   )
[/color][/b]  )
      )
 )
 (repeat (sslength ss)
   (setq ent (ssname ss 0))
   (entmod
     (subst (cons 40 (* (cdr (assoc 40 (setq e (entget ent)))) 2))
     (assoc 40 e)
     e
     )
   )
   (ssdel ent ss)
 )
)

 

EDIT: And yeah. use entmod approach like what tharwats code instead of command call.

Edited by pBe
Posted

Thank you Tharwat ! Here my code, if layer1 and layer3 have more than one circle, your lisp able to handle it ?

 

(defun chkToggle ()
   (setq item1(atoi(get_tile "item1"))) 
 (setq item2(atoi(get_tile "item2")))  
 (setq item3(atoi(get_tile "item3"))) 
 )

(defun s1()
 (setq dcl_id (load_dialog "sub.dcl"))
 (if (not (new_dialog "sub" dcl_id) ) (exit))
 (action_tile "item1" "(chkToggle)")   
 (action_tile "item2" "(chkToggle)")   
 (action_tile "item3" "(chkToggle)")   
 (action_tile "accept" "(setq ddiag 2)(done_dialog)")
 (action_tile "cancel" "(setq ddiag 1)(done_dialog)")
 (start_dialog)                                                                                                                                                                          
 (unload_dialog dcl_id)
 
 
 (if(= ddiag 1)
   (princ "\nCancelled!")
 )

 (if (= ddiag 2)
 
 (sc2)
  
  )
  );defun
  
  
(defun sc2 ()
(cond
     ((= item1 1) (setq sset (ssget "x"  (list '(8 . "layer1" ) '(0 . "CIRCLE")(cons 410 (getvar "CTAB"))))))
     ((= item2 1) (setq sset (ssget "x"  (list '(8 . "layer2" ) '(0 . "CIRCLE")(cons 410 (getvar "CTAB"))))))
     ((= item3 1) (setq sset (ssget "x"  (list '(8 . "layer3" ) '(0 . "CIRCLE")(cons 410 (getvar "CTAB"))))))
     )
 (if sset
   (repeat (setq i (sslength sset))
     (setq sn (ssname sset (setq i (1- i))))
     (entmod (subst (cons 40 (* (cdr (assoc 40 (setq e (entget sn)))) 4.)) (assoc 40 e) e)) 
   )
 )
(princ)
);defun
  

 

I updated my code with entmod which is better and faster .:)

 

In regard to your question , I did not get it , could you bring your codes or an example ?

Posted
Thank you Tharwat ! Here my code, if layer1 and layer3 have more than one circle, your lisp able to handle it ?

 

Yes it could . :)

 

Post the code of your DCL file .

Posted (edited)

Thanks ! Here my code of DCL file. If I selected both layer1 and layer3 at the same. This lisp able to scale two layers circle at the same times ?

sub : dialog { 
         label = "Select layer for scale circle"; 
          :column { 
           : boxed_column { 
            :text {
    key = "text"; 
               value ="nothing selected";
   }
    }
         : boxed_column  { 
     key = "mylist";
             : toggle {
               key = "item1";
               label = "layer1";
                value = "0";
             }
             : toggle {
               key = "item2";
               label = "layer2";
                value = "0";
             }

    : toggle {
               key = "item3";
               label = "layer3";
                value = "0";
             } 
           }
           : boxed_row { 
   : button {
               key = "accept";
               label = " Okay ";
               is_default = true;
             }   

             : button {
               key = "cancel";
               label = "Close";
               is_default = true;
               is_cancel = true;
             } 
           }   
         } 
}

Yes it could . :)

 

Post the code of your DCL file .

Edited by ahyin
Posted

I would suggest you populate a layer list and use list_box with with ; multiple_select = true;

and use that list for ssget filter

Posted
I would suggest you populate a layer list and use list_box with with ; multiple_select = true;

and use that list for ssget filter

 

Good idea pBe .

 

Besides that , I guess there is no need to the dialog since that is all about the a few names of Layers .

Posted
Good idea pBe .

 

Besides that , I guess there is no need to the dialog since that is all about the a few names of Layers .

 

True, in some cases. but with a dialog box you can make it generic so you wont be limited t0 particular number of layer names

I'm pretty sure the OP got the message loud and clear :)

Posted

Thank you for all of your suggestion, I will follow this direction to complete my program.

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