Create Points On Same Coordinate With All Existing Layer

Create Points On Same Coordinate With All Existing Layer

omorah
Collaborator Collaborator
1,391 Views
13 Replies
Message 1 of 14

Create Points On Same Coordinate With All Existing Layer

omorah
Collaborator
Collaborator

I believe I have, some time back, saw a LISP that would create points from layers in an existing CAD file.

 

That is, if I have a file with already created layers, I would need to create individual points on the same co-ordinate to match all the layers in that drawing. That is, if I have one hundred layers, I would like to create one hundred points, all on the same coordinate, corresponding to all the one hundred existing layers.

 

Please if you have come across the same LISP, please pass it on.

Thank you

 

0 Likes
Accepted solutions (2)
1,392 Views
13 Replies
Replies (13)
Message 2 of 14

dlanorh
Advisor
Advisor
Accepted solution

Try this. It handles locked layers by unlocking and relocking. You are asked to select the point to place all the points on each layer.

 

(defun rh:locked (c_obj / lst) (vlax-map-collection c_obj '(lambda (x) (cond ( (= :vlax-true (vlax-get-property x 'lock)) (setq lst (cons x lst)) (vlax-put-property x 'lock :vlax-false))))) lst)

(vl-load-com)

(defun c:lyrPts ( / c_doc c_spc c_lyrs lk_lst pt lyrlst n_obj)

  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        c_spc (vlax-get-property c_doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
        c_lyrs (vla-get-layers c_doc)
        lk_lst (rh:locked c_lyrs)
        pt (vlax-3d-point (getpoint "\nSelect Point for Layer Points : "))
  );end_setq
  
  (vlax-map-collection c_lyrs '(lambda (x) (setq lyrlst (cons (vlax-get-property x 'name) lyrlst))))
  
  (foreach lyr lyrlst
    (setq n_obj (vla-addpoint c_spc pt))
    (vlax-put-property n_obj 'layer lyr)
  );end_foreach
  
  (mapcar '(lambda (x) (vlax-put-property x 'lock :vlax-true)) lk_lst)
  (princ)
);end_defun

I am not one of the robots you're looking for

0 Likes
Message 3 of 14

hak_vz
Advisor
Advisor

I've coded this during my break at work, it's tested in Acad 2014 and it works ok.

(defun c:populate_points ( / *error* getlayers ss layers i j ly pt)
;copies all points in a drawing to all layers in a drawing
;hak_vz (05.11.2019.)
(defun *error* ()(princ))
(defun getlayers ( / l layers)
(setq l (tblnext "layer" T))
(while l (setq layers (cons(cdr (assoc 2 l)) layers) l (tblnext "layer")))
layers
)

(setq ss (ssget "X" '(( 0 . "POINT"))))
(setq layers (getlayers))
(setq i 0 j 0)
(while (< i (length layers))
	(setq ly (nth i layers))
	(while (< j (sslength ss))
			(setq pt (cdr (assoc 10 (entget (ssname ss j)))))
			(entmake
				(list
					(cons 0 "POINT")
					(cons 8 ly)
					(cons 10 pt)
				)
			)
	(setq j (+ j 1))	
	)
(setq i (+ i 1) j 0)
)
(setvar "cmdecho" 0)
(command "erase" ss "")
(setvar "cmdecho" 1)
(princ "\n Points have been replicated to all layers in this drawing")
(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 14

Kent1Cooper
Consultant
Consultant
Accepted solution

@omorah wrote:

.... if I have one hundred layers, I would like to create one hundred points, all on the same coordinate, corresponding to all the one hundred existing layers. ....


I think Message 3 misunderstands the request.  As to Message 2, it is not  necessary to unlock a Layer to draw on it.  [The current Layer can even be off, and you can still draw on it!]  If you were drawing all Points on the current  Layer and then CHPROP-ing them onto each Layer, the current Layer would need to be on and unlocked so that CHPROP could work on them.  If you were setting the current Layer successively to each Layer in the drawing and then drawing a Point on it, you'd need to deal with the possibility of Layers being off or frozen, and presumably set them back.

 

But it's not necessary to care about any of that -- using (entmake), you can even put Points directly on frozen  Layers [which can't be drawn on with a Point command, because they can't be current, though you could  draw one on a different Layer and CHPROP it onto a frozen one].  All you really need to be concerned about is that you can't put one on an Xref-dependent Layer.

(defun C:POAL (/ pt layinfo layname) ; = Points On All Layers
  (setq pt (getpoint "\nLocation of all Points: "))
  (while (setq layinfo (tblnext "layer" (not layinfo)))
    (if (not (wcmatch (setq layname (cdr (assoc 2 layinfo))) "*|*")); not an Xref Layer
      (entmake
        (list
          '(0 . "POINT")
          (cons 10 pt)
          (cons 8 layname)
        ); list
      ); entmake
    ); if
  ); while
  (princ)
); defun

 

Kent Cooper, AIA
0 Likes
Message 5 of 14

hak_vz
Advisor
Advisor

@Kent1Cooper  You may ask  to enter a point and replicate it to all other layer or you can create various points on different layers and then spread them across all other layer. In different scenario it's easy to change line or two of code. As with many topics, one have to be a wizard to figure out what author is asking for.  Its always easy to follow. Replays from @dlanorh  and me landed almost at the same minute.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 6 of 14

Kent1Cooper
Consultant
Consultant

@hak_vz wrote:

.... As with many topics, one have to be a wizard to figure out what author is asking for.  ....


In this case, I disagree.  I don't see anything difficult to understand in the part I quoted at the top of Message 4.

Kent Cooper, AIA
0 Likes
Message 7 of 14

ronjonp
Mentor
Mentor

I'd write it the same way as Kent with the exception of making sure that 'pt' is set.

(setq pt (cond ((getpoint "\nLocation of all Points [(0. 0. 0.)]: "))
	       ('(0. 0. 0.))
	 )
)
0 Likes
Message 8 of 14

hak_vz
Advisor
Advisor

In case that you have small number of this replicated points, creating them instantly may be a good approach. If you have 100 or 1000 of them, then I would create single point at one location, finish other work, and at the end assure that those points are replicated to all layers. Personally, I don't see a reason to use redundant points (i.e any data) in a drawing.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 9 of 14

omorah
Collaborator
Collaborator

I really appreciate your effort in helping me out.

When I applied it, it says "Too many arguments".

0 Likes
Message 10 of 14

omorah
Collaborator
Collaborator

Thank you so much for creating this wonderful LSP.

Well appreciated!

0 Likes
Message 11 of 14

omorah
Collaborator
Collaborator

Thank you so much for this LISP.

Works well. Well appreciated!

0 Likes
Message 12 of 14

Kent1Cooper
Consultant
Consultant

@dlanorh wrote:
....
(setq .... c_lyrs (vla-get-layers c_doc) .... (vlax-map-collection c_lyrs '(lambda (x) (setq lyrlst (cons (vlax-get-property x 'name) lyrlst)))) (foreach lyr lyrlst (setq n_obj (vla-addpoint c_spc pt)) (vlax-put-property n_obj 'layer lyr) );end_foreach ....

Isn't that going to run into trouble if you have XREF's?  That way of making a list of Layer names does not exclude XREF-dependent Layers, but you won't be able to assign those to the Points added.

Kent Cooper, AIA
0 Likes
Message 13 of 14

dlanorh
Advisor
Advisor

Hi Kent,

The original post stated

 

That is, if I have a file with already created layers, I would need to create individual points on the same
co-ordinate to match all the layers in that drawing. That is, if I have one hundred layers, I would like
to create one hundred points, all on the same coordinate, corresponding to all the one hundred existing
layers.

 with no mention of x-refs, or excluding their layers.

I am not one of the robots you're looking for

0 Likes
Message 14 of 14

hak_vz
Advisor
Advisor

@omorah wrote:

I really appreciate your effort in helping me out. When I applied it, it says "Too many arguments".


It expects that you already have a set of points that you want to replicate in all layers. Open your file with predefined layers, create your specific points and then apply your function - advantage. Before you replicate your specific points you may perform a checkup and resolve a mistake, and you can do this at any stage of drawing process. It uses ssget "X" that can be modified to look for a points in specific layers..... I guess you are not a novice and can do it.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes