Layfrz with object detection?

Layfrz with object detection?

KeithSWD
Advocate Advocate
1,584 Views
11 Replies
Message 1 of 12

Layfrz with object detection?

KeithSWD
Advocate
Advocate

I see this topic has been discussed some time ago but AFAIK without a solution...

 

I use LAYFRZ alot, and like other users I am constantly needing to change the selection level between Block and Entity.  Would it be possible to write a routine which detected the object being clicked (including blocks in xrefs... ), set the entity selection correctly in LAYFRZ and then applied the freeze?

 

Sadly this is way beyond my programming skills, but as a barter, I offer you a annotation-scale aware version of REVCLOUD... it works for me but I take no responsibility (reading it will reveal the level of my programming skill too...)  Smiley Wink

 

(defun c:cloud (/ *error* reply ans arcl osm ss obj)

  (if (= psarcl nil)
    (setq psarcl 5)
  )
  (setq	reply
	 (getreal
	   (strcat "Specify paperspace arc length required (Enter for "
		   (rtos psarcl)
		   "mm): "
	   )
	 )
  )
  (if (/= reply nil)
    (setq psarcl reply)
  )

  (setq arcl (/ psarcl (getvar "cannoscalevalue")))

  (initget "N O")
  (setq ans (getkword "\nDraw New or select Objects [N/O] <O>: "))

      (if (= ans "N") 
	(command "revcloud" "a" arcl arcl pause)
	(progn
  	(setq	ss (ssget '((0 . "ELLIPSE,POLYLINE,LWPOLYLINE,CIRCLE,POLYGON"))))
  		(repeat (setq i (sslength ss))
        	(setq obj (ssname ss (setq i (1- i))))
		    (command "revcloud" "a" arcl arcl "o" obj "n")
  		) ; end repeat

	) ;end progn
  ) ;end if

  (princ)

)

 

0 Likes
1,585 Views
11 Replies
Replies (11)
Message 2 of 12

ВeekeeCZ
Consultant
Consultant

Would you elaborate what is the correct behaviour for you?

 

 

If you pick a block what the setting should be changed to? 

If you pick a simple entity what the setting should be changed to?

0 Likes
Message 3 of 12

KeithSWD
Advocate
Advocate

Hi -

 

I'd like it so that when I click on a block object (either within the current drawing or an xref) the 'block nesting' is set to Block, and the freeze applied accordingly (freezing the block insertion layer in the current or xref drawing)

 

When I click on an entity (in current or xref), the block nesting level is set to Entity, and the entity's layer is frozen.

 

It would also be great if it caught the situation where layer 0 would be frozen as a result, and asked the user if they really want to freeze layer 0. (Normally I don't, and I go to the xref and move the offending block into another layer).

 

thanks

Keith

0 Likes
Message 4 of 12

Kent1Cooper
Consultant
Consultant

@KeithSWD wrote:

.... 

I'd like it so that when I click on a block object (either within the current drawing or an xref) the 'block nesting' is set to Block, and the freeze applied accordingly (freezing the block insertion layer in the current or xref drawing)

 

When I click on an entity (in current or xref), the block nesting level is set to Entity, and the entity's layer is frozen.

 

It would also be great if it caught the situation where layer 0 would be frozen as a result, and asked the user if they really want to freeze layer 0. ....


You should be able to use LayerQuellPick.lsp, available here.  Its LFP command [= Layer Freeze by Picking] works just as you describe.  [To freeze the Layer of a Nested object, you have to use the LFPN command instead -- it's a different command, rather than an option within one command.]  The commands with O instead of F in their names "quell" Layers by turning them Off rather than Freezing.  And the -N commands recognize a Layer-0 nested entity and "move up" until they encounter a non-0 Layer to quell instead of Layer 0 [see the end of the first Comment].  But it will quell Layer 0 if a top-level entity picked is on it.  I suppose it could be altered to ask whether instead.

Kent Cooper, AIA
0 Likes
Message 5 of 12

KeithSWD
Advocate
Advocate

Thanks Kent,

 

I had a quick look at that, but on picking a block in an xref, both LFP and LFPN froze the layer the xref was inserted on, so the entire xref disappeared. LayFrz with Block level set to 'Block' will just freeze the xref layer the block is on.  It also doesn't give you the feedback on the command line telling you what layer it has frozen/turned off, which is handy so you know for next time (I am often doing this with drawings from other consultants).

 

Also, if a different command is required for different situations, it seems like you would need to know whether you are picking a block or an entity beforehand. I often don't, hence wanting the routine to sort that out for me and act accordingly.

0 Likes
Message 6 of 12

ВeekeeCZ
Consultant
Consultant

I must be missing something. If I set "Block Nesting Level" to Block, it works exactly as you're asking for (tested on ACAD 2015). This setting does not apply on selection of a single entity - no matter what it currently set, it will always freeze its layer. This works corrently even if you select something in a xref!

 

Only issue left is Layer 0 control. This we can add.

0 Likes
Message 7 of 12

KeithSWD
Advocate
Advocate

 

With LAYFRZ,  the point is that if you are working with an unfamiliar drawing, maybe xref'd into your own drawing, you might be picking linework that MAY be part of a block, or MAY be an entity.  If you get it wrong, the wrong layer is frozen and you have to UNDO to get back, then change the Block level option and repeat the action.  On a big complex drawing, undo-ing a freeze command can take a long time (I don't know why, freezing happens almost instantaneously, but it seems a full regen is required to undo it).

 

What I want the routine to do is to determine itself whether an single entity or block has been picked, set the block level option accordingly and perform the freeze.

 

Does that make sense?

0 Likes
Message 8 of 12

ВeekeeCZ
Consultant
Consultant

I think the only issue is that you've lost the confidence. You should have set the default, which is the "BLOCK" for layer nested setting, and NEVER change it. Then you will know that it freezes the block's layer or object's layer if that was a linework. And you will also know that you're unable to pick nested object and freeze its layer.

 

Keep in mind that "Layer Nested Setting" has NO EFFECT on simple linework despite the name "Entity" - which better should be called "nested Entity".

 

If you don't trust the setting, you can use following code which always pre-set this setting:

 

(defun c:LayFrzBlock nil
  (command "_.LAYFRZ" "_Settings" "_Block" "_Block")
  (princ)
)

We could also undefine the original command and replace it with this one.

 

 

;---- 

If there ever be the case that you want to freeze nested object layer, use this command.

 

(defun c:LayFrzNested nil
  (command "_.LAYFRZ" "_Settings" "_Block" "_Entity")
  (princ)
)

 

0 Likes
Message 9 of 12

KeithSWD
Advocate
Advocate

Sorry but in my world that doesn't work, I am constantly flipping back and forth between 'Block' and 'Entity', and trust me, I only take the trouble to change it because I am not getting the result I want.  Most often, I will be setting viewport layer visibility and during a single layfrz command I might go back and forth between the two levels  more than once.

 

I'll keep doing that for now! 

0 Likes
Message 10 of 12

hencoop
Advisor
Advisor

Hi all,

 

My personal solution to the problem is a dialog that shows the layers related to the selection and some information about them in a dialog that allows me to select the desired layer and action to take.  I call it SHOLAY. 

 

You can download it and the required supporting subroutines listed below it for free here: SHOLAY.LSP  It requires a DCL file too that is here: SHOLAY.DCL

 

I rarely use AutoCAD's layer dialog since I began using SHOLAY.  If I can see it I can do any layer operation on the layer(s) I see.

 

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 11 of 12

john.uhden
Mentor
Mentor

I have an old LAYPICKFRZ.lsp program that probably does exactly what you want.  You pick objects to get their layer name and can turn nested selection on or off at will.  It would require some repackaging, but I would be willing to share if desired.

John F. Uhden

0 Likes
Message 12 of 12

ВeekeeCZ
Consultant
Consultant

This routine I've made for myself. Not sure but it might fill your requirements too. If you still care...

 

All it does is LAYFRZ nested 'Entity' type unless it's '0', else 'Block' type.

If the layer of non-nested layer is 0 then it asks what to do.

Unable to freeze xref layer.

Unable to freeze nested 0 layer unless it's a layer of a block.

 

(vl-load-com)

(defun c:LayFrzNested ( / *error* doc ent lay lst) ; freeze nested layer: 'Entity' type unless it's '0', else 'Block' type.
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if (acet-layerp-mark) (acet-layerp-mark nil))
    (vla-endundomark doc)
    (princ))
  
  (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  (acet-layerp-mark T)
  
  (while
    (progn
      (setvar 'ERRNO 0)
      (initget "Undo")
      (setq ent (nentsel "\nSelect an object on the layer to be frozen [Undo]: "))
      (cond ((= 7 (getvar 'ERRNO)) (princ "\nNothing selected."))
	    
	    ((null ent) nil) ; exit

	    ((and (= "Undo" ent) (not lst)) (princ "\nNothing to undo.")) 
	    
	    ((and (= "Undo" ent) lst)
	     (vl-catch-all-apply 'vla-put-freeze (list (vlax-ename->vla-object (tblobjname "LAYER" (car lst))) :vlax-false))
	     (princ (strcat "\nLayer " (car lst) " has been thawed."))
	     (setq lst (cdr lst))
	     (vla-regen doc acActiveViewport)
	     T)
	    	    
	    (T
	     (and (setq lay (cdr (assoc 8 (entget (car ent)))))
		  (setq lay (cond ((and (= lay "0") (= 2 (length ent)))
				   (initget "Yes")
				   (cond ((getkword "\nTurn off layer '0' of non-nested object? [Yes] <no>: ")) (lay)))
				  ((and (= lay "0") (= 4 (length ent)))
				   (cdr (assoc 8 (entget (car (last ent))))))
				  (lay)))
		  (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-freeze (list (vlax-ename->vla-object (tblobjname "LAYER" lay)) :vlax-true))))
		  (princ (strcat "\nLayer " lay " has been frozen."))
		  (setq lst (cons lay lst)))
	     T))))
  (*error* "end")
  )

 

0 Likes