Jump to content

Isolate by target type


samifox

Recommended Posts

hi

 

sometimes when i get drawing from others, i need to map all entities to proper layer, for example dimention are laying on different layers, you want them on one layer right?.

 

Isolate is great but it wont solve the problem mentioned above becuse its based on layer. so i wrote a lisp (my first working one ;)) to isolate an entity based on the target type , meaning if you choose dimention line, they all are isolated regardless of the layer they are laying on.

 

in the next step user will have the option to:

 

Update : restart

New : option to put all isolated entites on a new layer

Restore: unisolate and terinate the function

 

ill be happy to have your seggestion on improving the code

Thanks

S

 

(setq TEMPTARGETLAYERNAME "SG_TEMP")

(defun C:Test (/ ent sset i e cl)
 (setq ent (entget (car (entsel "Select target entity\n"))))
 (setq sset (ssget "_X" (list (assoc 0 ent)))) ;_select all entities with target type


 (if (not (tblsearch "LAYER" TEMPTARGETLAYERNAME)) ;_if target  layer doesnt  exist, create it
     
   (entmake (list '(0 . "LAYER")
	   '(100 . "AcDbSymbolTableRecord")
	   '(100 . "AcDbLayerTableRecord")
	   '(70 . 0)
	   (cons 2 TEMPTARGETLAYERNAME)
	   (cons 62 2)
     )
   )

   
 ) ;_if

(setvar "clayer" TEMPTARGETLAYERNAME)

 (setq i 0)
 (while (< i (sslength sset))
   (setq e (entget (ssname sset i)))
   (entmod (subst (cons 8 TEMPTARGETLAYERNAME) (assoc 8 e) e)) ;_replace the sset entites layer to target
   (setq i (1+ i))
 )


 (while (setq la (tblnext "LAYER" (null la))) ;_set all layers (except target) to froozen
   (if	(not (equal (assoc 2 la) (cons 2 TEMPTARGETLAYERNAME)))
 
     (progn
(setq ob (tblobjname "LAYER" (cdr (assoc 2 la))))
(setq ladef (entget ob))
(if (assoc 70 ladef)
  (entmod (subst (cons 70 1) (assoc 70 ladef) ladef))
  (entmod (append la '((70 . 1))))
)
     )
   )
 )

 (initget 7 "Restore Update New")
 (setq case (getkword "[Restore/Update/New]"))

 (cond
   ((eq case "Restore") (alert case))
   ((eq case "Update") (alert case))
   ((eq case "New") (alert case))
   (T case)
   )
   
)

Link to comment
Share on other sites


 (setq ent (entget (car (entsel "Select target entity\n"))))
 (setq sset (ssget "_X" (list (assoc 0 ent)))) ;_select all entities with target type

 

(if (setq ent (car (entsel "\n Select target entity")))
 (setq sset (ssget "_X" (list (assoc 0 (entget ent)))))
 )

 (not (equal (assoc 2 la) (cons 2 TEMPTARGETLAYERNAME)))

 

(not (equal (cdr (assoc 2 la)) TEMPTARGETLAYERNAME))

   (if (assoc 70 ladef)
     (entmod (subst (cons 70 1) (assoc 70 ladef) ladef))
     (entmod (append la '((70 . 1))))
   )

 

 

(entmod
 (subst (cons 70 (1+ (cdr (assoc 70 (setq ladef (entget ob))))))
        (assoc 70 ladef)
        ladef
 )
)

Link to comment
Share on other sites

How you would unisolate?

 

Replace the 1+ with 1- in my previous post .

 

I was thinking about setting undo mark...

 

Read about functions vla-startUndomark and vla-endundomark

Link to comment
Share on other sites

(if (setq ent (car (entsel "\n Select target entity")))
 (setq sset (ssget "_X" (list (assoc 0 (entget ent)))))
 )

 

your code make more sense, but i wonder if it has something to do with efficiency or just readability purpose?

 

(not (equal (cdr (assoc 2 la)) TEMPTARGETLAYERNAME))

 

you right, no need to compare all but just the value

 

(entmod
 (subst (cons 70 (1+ (cdr (assoc 70 (setq ladef (entget ob))))))
        (assoc 70 ladef)
        ladef
 )
)

 

this one is interesthing, you jump from 70.1 to 70.2 , i cant understand why?

 

Thanks

Shay

Link to comment
Share on other sites

this one is interesthing, you jump from 70.1 to 70.2 , i cant understand why?

 

Thanks

Shay

 

If a layer is locked , the dxf 70 would be equal to 1 then if you wanted to freeze it , you should add to that dxf value to keep the layer locked as it is and would freeze it as well .

Link to comment
Share on other sites

If a layer is locked , the dxf 70 would be equal to 1 then if you wanted to freeze it , you should add to that dxf value to keep the layer locked as it is and would freeze it as well .

WOOW it was smart thing to do :)

Link to comment
Share on other sites

hi

 

this is the code i manage to write so far , have some questions based on this code

 

1.how to prevent user of missing the entity when asked to select one?

2. how would you write the main function (isotyp) with (and) instead of nesting if's)

3.how to improve the code to be shorter, efficient and easy to follow?

4.why osnap is not going off

 

(setq TEMPTARGETLAYERNAME "SG_TEMP")
(setq TEMPTARGETLAYERCOLOR 5)

(setq ISOLATED T)
(setq ISOSET nil) ;_hold isolated layers data
(setq ISOVIS 0) ;_set isolated to frozen or locked


;;----------------=={ Isolate by type }==---------------------;;
;;                                                            ;;
;;  Isolate all drawing's entityes by the choosen             ;;
;;  target type.                                              ;;
;;                                                            ;;
;;------------------------------------------------------------;;
;;  Author: Shay Gaghe, Copyright © 2014                      ;;
;;------------------------------------------------------------;;
;;---Function Syntax : isotyp , unisotype(not active)         ;;
;;-- Current Version : 0.1                                    ;;
;;-- Version History : 0.0    Date: 11.04.14                  ;;
;;------------------------------------------------------------;;



;;----------------=={ SG:applyToSset }==----------------------;;
;;                                                            ;;
;;  set all the givan selection set's members to a gien dxf   ;;
;;  entry and value.                                          ;;
;;------------------------------------------------------------;;
;;  Author: Shay Gaghe, Copyright © 2014                      ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  sset   - a selection set                                  ;;
;;  dxfe   - dxf entry to substitue                           ;;
;;  dxfv   - the new dxf value                                ;;
;;------------------------------------------------------------;;
(defun SG:applyToSset  (sset dxfe dxfv / e i n)
 (setq i 0)
 (while (< i (sslength sset))
   (setq e (entget (ssname sset i)))
   (setq n (entmod (subst (cons dxfe dxfv) (assoc dxfe e) e)))
   (setq i (1+ i))
   )
 T
 )

;;----------------=={ SG:createLayer }==----------------------;;
;;                                                            ;;
;;  creates a new layer withe <name> name and <color> color.  ;;
;;------------------------------------------------------------;;
;;  Author: Shay Gaghe, Copyright © 2014                      ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  name   - a string representing the layer name             ;;
;;  color  - integer representing the layer color             ;;
;;------------------------------------------------------------;;
;;  Returned value:                                           ;;
;;  entity name of the name created entity                    ;;
;;------------------------------------------------------------;;
(defun SG:createLayer  (name color)
 (entmakex (list '(0 . "LAYER")
	  '(100 . "AcDbSymbolTableRecord")
	  '(100 . "AcDbLayerTableRecord")
	  '(70 . 0)
	  (cons 2 name)
	  (cons 62 color)
	  )
    )
 )

;;----------------=={ SG:applyToAllLayers }==--------------------;;
;;                                                            ;;
;;  apply a givan property and value to all drawing layers    ;;
;;  expet the current current one.                            ;;
;;------------------------------------------------------------;;
;;  Author: Shay Gaghe, Copyright © 2014                      ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  dxfe   - dxf entry to substitue                           ;;
;;  dxfv   - the new dxf value to apply                       ;;
;;------------------------------------------------------------;;
(defun SG:applyToAllLayers  (dxfe dxfv / la ob ladef)
 (setq ISOLATED T)
 (while (setq la (tblnext "LAYER" (null la))) ;_set all layers (except target) to froozen
   (if	(not (equal (cdr (assoc 2 la))
	    (getvar "CLAYER")
	    ))
     (progn
(setq ob (tblobjname "LAYER" (cdr (assoc 2 la))))
(setq ladef (entget ob))
(setq ISOSET (cons ladef ISOSET))
(if (assoc dxfe ladef)
  (entmod
    (subst
      (cons dxfe dxfv)
      (cons dxfe
	    (cdr (assoc dxfe (setq ladef (entget ob)))))

      ladef
      )
    )
  (entmod (append la '((dxfe . dxfv))))
  )
)
     )
   )
 )

(defun C:isotyp(/ ent sset i e cl f)
 (setvar "CMDECHO" 0) ;_turn off native command text
 (setvar "OSMODE" 0) ;_turn off osnap

 (command "undo" "m") ;_set undo mark 

 (if (setq ent ;_ask user to select entity, if user miss it, program is terminated
     (car (entsel
	    "\n Select the entity type you want to isolate \n")))
   (if	(setq sset (ssget "_X" (list (assoc 0 (entget ent))))) ;_get all entities of the selected type as a selection set
     (if (< 1 (sslength sset))
(if (not (tblsearch "LAYER" TEMPTARGETLAYERNAME)) ;_make sure the temp layer is not in use
  (if (SG:createLayer ;_create layer
	TEMPTARGETLAYERNAME
	TEMPTARGETLAYERCOLOR)
    (if	(SG:applyToSset sset 8 TEMPTARGETLAYERNAME) ;_move all members of sset to the temp layer
      (progn
	(setvar "clayer" TEMPTARGETLAYERNAME) ;_set temp layer as the current layer
	(cond
	  ((eq ISOVIS 0) (SG:applyToAllLayers 70 1)) ;_set all layers exept current to froozen
	  ((eq ISOVIS 1) (SG:applyToAllLayers 70 4) ;_set all layers exept current to lock

	   ))

	(princ
	  (strcat
	    "\NAll entities of the type "
	    (cdr (assoc 0 (entget (ssname sset 1))))
	    " has been isolated"
	    )
	  )
	) ;_progn
      (princ "\Ncannot apply properties to selection set")
      ) ;_if
    (princ "\NTemp layer could not e created")
    ) ;_if
  (princ (strcat "\nLayer "
		 TEMPTARGETLAYERNAME
		 "is in use terminate function"
		 )
	 )
  ) ;_if
(princ "no entities of this type")
) ;_if
     (princ "cant get entities from database")
     ) ;_if
   (princ "\nUser didnt select en entity or exit prematurly")
   )
 (princ)
 )

Link to comment
Share on other sites

meaning what?

If you do not follow your posts , that means you are not happy with the input and not thankful at all and this would give a signal to users not to have the same willing to help the same user anymore .

Link to comment
Share on other sites

tharwat is only you with this attitude. all users can understand not all users have the time and place to follow posts. im thankfull and happy to be part of this community without all of you all i wouldnt know anything.

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