Jump to content

Recommended Posts

Posted (edited)

Goal:

To select all the the objects I want to manipulate at once using a selection window, then the lisp program modifies the properties of just the Circle Entities in that selection. Below I am currently just changing the color property. After modifying the circles, I would like to modify all polyline & LWpolylines with a separate color change. I do not want to have to select the objects twice. Hopefully if this is possible I would like to followup saving Mtext or Text entites in another list.

 

Below is where I have landed after two days of searching for solution. I am not a novice to programming but am with the lisp language. My assumption is that the ssget "_P" command can only be used once. The lisp runs and works for changes the circle entities, but not he polylines.( Command Output shown after the lisp script below)

 

 

 

(defun c:FGT (/ ss sf1 sf2 )
   (princ "\nSelect objects to export: ")
   (setq ss (ssget  '((-4 . "<or") (0 . "CIRCLE") (0 . "MTEXT") (0 . "TEXT") (0 . "LWPOLYLINE") (0 . "POLYLINE") (-4 . "or>"))))
 		(setq sf1 (ssget "_P" '((0 . "CIRCLE"))))
 		(command "_chprop" sf1 "" "c" "150" "" )
 		(setq sf2 (ssget "_P" '((-4 . "<or") (0 . "POLYLINE") (0 . "LWPOLYLINE") (-4 . "or>"))))
 		(command "_chprop" sf2 "" "c" "green" "" )
 )

 

COMMAND:

Command: FGT

Select objects to export:

Select objects: Specify opposite corner: 107 found

Select objects:

_chprop

Select objects: 104 found

Select objects:

Enter property to change [Color/LAyer/LType/ltScale/LWeight/Thickness/TRansparency/Material/Annotative]: c

New color [Truecolor/COlorbook] : 150

Enter property to change [Color/LAyer/LType/ltScale/LWeight/Thickness/TRansparency/Material/Annotative]:

Command: _chprop

Select objects:

Command: FGT

Unknown command "FGT". Press F1 for help.

Command: c Unknown command "C". Press F1 for help.

Command: green Unknown command "GREEN". Press F1 for help.

Command: FGT

Unknown command "FGT". Press F1 for help.

Command: nil

Command:

Automatic save to C:\Users\Wesley\appdata\local\temp\Test_1_6214_5330.sv$ ...

Command:

Command: 'VLIDE

Command:

Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:

Edited by SLW210
Code Tags
  • 2 weeks later...
Posted

Perhaps something like this :

 

 

(defun c:FGT ( / ss sf1 sf2 i e ee )
 (while
   (or
     (prompt "\nSelect objects on unlocked layer(s) to export...")
     (not (setq ss (ssget "_:L" '((0 . "CIRCLE,MTEXT,TEXT,*POLYLINE")))))
   )
   (prompt "\nEmpty sel. set... Retry selecting entities again...")
 )
 (setq sf1 (ssadd))
 (setq sf2 (ssadd))
 (repeat (setq i (sslength ss))
   (setq e (ssname ss (setq i (1- i))))
   (cond
     ( (= (setq ee (cdr (assoc 0 (entget e)))) "CIRCLE")
       (ssadd e sf1)
     )
     ( (wcmatch ee "*POLYLINE")
       (ssadd e sf2)
     )
   )
 )
 (command "_.chprop" sf1 "" "_c" "150" "")
 (command "_.chprop" sf2 "" "_c" "green" "")
 (princ)
)

HTH., M.R.

Posted

Here is one way. Take the original selection set and iterate it, creating two new selection sets along the way.

I'm not saying this is the best way, or most optimized.

 


(defun c:FGT (/ ss w k c1 c2 tmp lst etp )
 (princ "\nSelect objects to export: ")
 (setq	ss (ssget '((-4 . "<or")
	    (0 . "CIRCLE")
	    (0 . "MTEXT")
	    (0 . "TEXT")
	    (0 . "LWPOLYLINE")
	    (0 . "POLYLINE")
	    (-4 . "or>")
	   )
   )
 )
 (if ss
   (progn
     (setq w  (sslength ss)
    k  0
    c1 (ssadd)
    c2 (ssadd)
     )
     (while (< k w)
(setq tmp (ssname ss k))
(setq lst (entget tmp))
(setq etp (cdr (assoc 0 lst)))
(cond ((eq etp "CIRCLE")
       (setq c1 (ssadd tmp c1))
      )
      ((or (eq etp "POLYLINE") (eq etp "LWPOLYLINE"))
       (setq c2 (ssadd tmp c2))
      )
)
(setq k (1+ k))
     )
   )
 )
 (command "_chprop" c1 "" "c" "150" "")
 (command "_chprop" c2 "" "c" "green" "")
)

Posted

@ R.K.

 

 

One remark, chprop command won't work well if selected entities are on locked layer(s), and your firstly coded sel. set is not preventing this from happening... Consider adding "_:L" into filter...

Posted

Thanks @marko_ribar,

 

I didn't touch that part of @Hailmac's code. I'm sure he/she will take that into consideration.

Posted

Hi there..

 

As advice #1 I would rather point out that you can use some kind of conditional to deal with different entity types instead of having to manage multiple selection sets. The following will do that and also skip any objects on locked layers while also not using any calls to commands. Can also modify multiple properties for an item type, like circles in the example will be changed color to 150 and lineweight on .25mm

(defun c:FGT (/ criteria ss cnt vlitm )
 ;Jef! 2018-07-09 http://www.cadtutor.net/forum/showthread.php?104612-Multiple-Pulls-from-Selection-Set
 (princ "\nSelect objects to export: ")
 (setq criteria '(("CIRCLE" . (("COLOR" . 150)("Lineweight" . 25)))("POLYLINE" . (("COLOR" . 3)))("LWPOLYLINE" . (("COLOR" . 3)))))
 (if (setq ss (apply 'ssget (list (cons '(-4 . "<or") (append (mapcar '(lambda (x) (cons 0 (car x)) )criteria) '((-4 . "or>")))))))
       (repeat (setq cnt (sslength ss))
         (setq vlitm (vlax-ename->vla-object(setq itm (ssname ss (setq cnt (1- cnt))))))
         (if (= 4 (logand 4 (cdr (assoc 70 (entget (tblobjname "layer" (cdr (assoc 8 (entget itm)))))))))
             (princ "\nItem on frozen layer have been ignored")
             (foreach prop (cdr (assoc (cdr (assoc 0 (entget itm))) criteria))
               (vlax-put-property vlitm (car prop) (cdr prop))
             )
         )
       )
 )
 (princ)
)

interesting fact is that apparently using apply 'ssget enables implied (pre selected) selection too. I just learned something here! :D

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