Jump to content

new layer for every LINE


ktbjx

Recommended Posts

Scenario i will make a line and that line will be on the new layer with its count

 

is it possible to make a lisp that i can use that makes a layer and its count as the layer name???

so that every line i make will have different layer counts? and its it possible that i can set what number to start with?

 

i tried making... i think i got the new layer on every line i make, but i wanna make it one step further.

what if i wanna make multiple line on a layer? without loosing the line count, the next layer it will make should be the next count. something like the DWG file...

 

can someone help me do it please?

 

here is the code i got so far:

(defun c:TestLINE (/ numero contstring)
   (if (and (setq numero (getint "\nEnter HoleID: "))
     )               
   
(while T
     (if (not
           (tblsearch
             "LAYER"
         (setq contstring (strcat "" (itoa numero)))
     )
         )
   
       (command "_layer" "m" contstring "" "_.line" pause pause "")
   
   )
     (setq numero (+ numero 1))
   )

 )
   (princ)
)

 

if you will look at the drawing, you will understand what i mean about the line counts....

Sample Cad composite.dwg

Link to comment
Share on other sites

i think i kinda got it???

i know its ugly, but atleast i tried....

(defun testes ()
  ; (if (and (setq numero (getint "\nEnter HoleID: "))
  ;   )               
   
(while T
     (if (not
           (tblsearch
             "LAYER"
         (setq contstring (strcat "" (itoa numero)))
     )
         )
   
       (command "_layer" "m" contstring "" "_.line" pause pause "")
   
   )
     (setq numero (+ numero 1))
   )

; )
   (princ)
)


(defun c:testestes (/ numero chcut cntr contstring)
   (setq numero (getint "\nEnter HoleID: "))
   (while T
       (setq chcut (getint "\nEnter # of CHCUTS: "))
       (setq cntr 1)
      (if (= chcut 1)
      (testes)
      )
    (if (not
           (tblsearch
             "LAYER"
                     (setq contstring (strcat "" (itoa numero)))
                     )
         )
       (command "_layer" "m" contstring "") 

   )
   
      (while (<= cntr chcut)
           (command "_.line" pause pause "")
            (setq cntr (+ cntr 1))
   (setq numero (+ numero 1))
   )
)

   (princ)
)

Link to comment
Share on other sites

This is a pline but the same with Line, replaces the need for howmany.

 

; create pline by picking points press enter when finished
(command "_pline")
(while (= (getvar "cmdactive") 1 ) (command pause)
)

 

My attempt others I am sure will provide something as well.

(defun laychk (lay  / )
(if (not (tblsearch  "LAYER" (itoa lay)))
(command "_layer" "m" (itoa lay) "")
)
)
(defun c:testes ()
(if (/= numero nil)
(setvar 'clayer (itoa numero))
(progn
(setq numero (getint "Enter a number"))
(laychk numero)
)
)
(setq continue "Y")         
(while (=  continue "Y")
(command "_pline")
(while (= (getvar "cmdactive") 1 ) (command pause)
)
(setq numero (+ numero 1))
(laychk numero)
(if (= (setq continue (Getstring "Press <Cr> to continue any key to exit")) "")
(setq continue "Y")(setq continue "N"))
)
(princ)
)
(c:testes)

Edited by BIGAL
Link to comment
Share on other sites

To Whom It May Concern.

 

Testes

 

The functions of the testes are to produce both sperm and androgens, primarily testosterone.

 

One of the better function names.

Link to comment
Share on other sites

I completely do not understood what OP's after:

Like you are drawing objects, and the layer changes with their count -

but what happens if you manually change the current layer?

what happens if you manually change the layer of some objects?

 

Heres what I've played with:

(vl-load-com) (princ)

; CountWithLayer reactor thats not full-proof.

(defun CountWithLayer:CB ( rtr args / o lyr f n )
 (cond 
   ( (not (and *Han* *Lyrs*)) (prompt "\n#1") )
   ( (vl-catch-all-error-p (setq lyr (vl-catch-all-apply 'vla-Item (list *Lyrs* (getvar 'clayer))))) (prompt "\n#2") )
   (
     (not 
       (setq o 
         ( ; alternative to (entlast) with ActiveX
           (lambda ( / spc r )
             (setq spc (vla-get-Block (vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object)))))
             (setq r (vl-catch-all-apply 'vla-Item (list spc (1- (vlax-get-property spc 'Count)))))
             (if (not (vl-catch-all-error-p r)) r)
           )
         )
       )
     ); not
     (prompt "\n#3")
   )
   ( (not (vlax-property-available-p o 'Layer)) (prompt "\n#4") )
   ( (eq o *lasto*) (prompt "\n#5") )
   ; ( (not (wcmatch (vlax-get-property *lasto* 'Layer) "cnt_*")) (prompt "\n#6") ) ; not perfect
   ; ( (not (eq (vlax-get-property lyr 'Name) (vlax-get-property *lasto* 'Layer))) (prompt "\n#6") )
   ( (not (setq f (eval (cdr (assoc (vlr-current-reaction-name) '((:VLR-objectAppended . 1+)(:VLR-ObjectErased . 1-)(:VLR-ObjectUnerased . 1+))))))) (prompt "\n#7") )
   ( (not (eq *Han* (vla-get-Handle lyr))) (prompt "\n#8") )
   ( (not (eq 'INT (type (setq n (read (vl-string-left-trim "cnt_" (vlax-get-property lyr 'Name))))))) (prompt "\n#9") )
   ( (not (vlax-write-enabled-p lyr)) (prompt "#10") )
   ( (vl-catch-all-apply 'vlax-put-property (list lyr 'Name (strcat "cnt_" (itoa (f n))))) ) ; duplicate layer name possibility
 ); cond
); defun CountWithLayer:CB 



( ; Note Layers that wcmatch to "cnt_*" must be erased
 (lambda ( rtrnm / e)
   (setq *Lyrs* (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))))
   (setq *Han* (vla-get-Handle (vla-Add *Lyrs* "cnt_0")))
   (and (setq e (entlast)) (setq *lasto* (vlax-ename->vla-object e)))
   (setvar 'clayer "cnt_0")
   (foreach rtr (cdar (vlr-reactors :VLR-AcDb-reactor)) (if (= rtrnm (vlr-data rtr)) (vlr-remove rtr)) )
   (vlr-set-Notification
     (vlr-AcDb-reactor rtrnm '((:VLR-objectAppended . CountWithLayer:cb)(:VLR-ObjectErased . CountWithLayer:cb)(:VLR-ObjectUnerased . CountWithLayer:cb)))
     'Active-Document-Only
   ); vlr-set-Notification
 ); lambda
 "MyTestReactor"
)

 

CountWithLayer.gif

 

So the above creates only one layer, and changes its name constantly.

Although my code is not fully error-proof. :glare:

Link to comment
Share on other sites

To Whom It May Concern.

 

Testes

 

The functions of the testes are to produce both sperm and androgens, primarily testosterone.

 

One of the better function names.

 

Sorry for that, it was supposed to be tests, but i made a typo and i got lazy so i just roll with it and used it.

 

I completely do not understood what OP's after:

Like you are drawing objects, and the layer changes with their count -

but what happens if you manually change the current layer?

what happens if you manually change the layer of some objects?

The idea is, i draw a line and the layername will be the count of lines i have been drawing.

So if i started on drawing a single line, thats count 1 (thats my layername 1) and then i continue drawing another line, thats count 2( thats layername 2) and so on...

Making a single line on every layer is easy, as you can see on my ugly code i just created a layer and i draw a line, then it loops.

 

My concern is, on a single layer, i want to draw 2 or more lines! But still keeping track on the count, so that when i make another layer, it will be the last number on my count.

 

So if lets say im on layer 5 and ill be drawing 2 lines

My next layername should be 7.

Lets continue, im on layer 7 this time, and ill be drawing 4 lines,

My next layer should be layer 10...

Link to comment
Share on other sites

I completely do not understood what OP's after:

 

Same here. Does it create an infinite number of layers as the user continues to create lines/objects?

 

EDIT: oops did not see the post from the OP there :lol:

Link to comment
Share on other sites

Of what possible is this routine? What are you actually trying to accomplish by naming layers based upon the total number of lines drawn to that point?

Link to comment
Share on other sites

Of what possible is this routine? What are you actually trying to accomplish by naming layers based upon the total number of lines drawn to that point?

 

So that i can dataextract them all with all those xyz coords plus LAYERNAME

Since it has numbers, it will be easier for me to manipulate the data on the next step.

Furthermore, since it has count. I will not keep track on it anymore, focusing on other datas, thus helping me work faster

Link to comment
Share on other sites

I thought that Data extraction is based on the order in which entities are created. So, to me, the need for this lisp is tautology.

 

Youre right, so how can i pinpoint exactly those lines created with the same id?(thats the layername)

Im dealing with old underground historical maps. Those lines represents the sample cuts where the samplers and mappers got their rock samples. And those lines have individual gold and copper values... The lines with the same IDs are "face" samples, which contains different line counts. And The lines with single IDs are wall samples. But not all single IDs are wall samples, there are other face samples with only 1 IDs.

Thats all in a single jpeg file that i have to digitize and input the gold and copper values on every single line.

I want to make this lisp to help me make my work faster.

How is this tautology????

If you gave a better idea then please im all ears!

 

A single map can contain 80k samples. Thats 80k lines for me to input gold and copper. Thats 80k lines for me to input which lines should have the same IDs, and which lines should be singles...

If you have a better idea, please do tell..

Link to comment
Share on other sites

Maybe post your drawing. In the meantime, give this a try:

(defun c:foo (/ i n p1 p2 p3 s)
 (setq	i (cond	((setq s (ssget "_x" '((0 . "line"))))
	 (1+ (apply 'max
		    (mapcar '(lambda (x) (fix (atof (cdr (assoc 8 (entget x))))))
			    (mapcar 'cadr (ssnamex s))
		    )
	     )
	 )
	)
	(1)
  )
 )
 (while
   (progn
     (setq n 0)
     (while (and (or (setq p1 p3) (setq p1 (getpoint "\nSpecify first point: ")))
	  (setq p2 (getpoint p1 "\nSpecify next point: "))
     )
(setq p3 nil)
(and (entmakex (list '(0 . "line")
		     (cons 10 p1)
		     (cons 11 p2)
		     (cons 8 (itoa i))
		     (cons 62
			   (if (= 0 (rem i 255))
			     1
			     (rem i 255)
			   )
		     )
	       )
     )
     (setq n (1+ n))
     (princ (strcat "\nLine created on layer [" (itoa i) "]"))
)
     )
     (if
(setq p3 (getpoint (strcat "\nSpecify first point for next layer [" (itoa (+ n i)) "]: ")))
 (setq i (+ n i))
     )
   )
 )
 (princ)
)

Edited by ronjonp
Link to comment
Share on other sites

2nd try:

(setq *MyCountLyrs*
 '( ; Layer Name, Initial count
   ("Layer1" 0) ;<- fill here
   ("Layer2" 0) ;<- fill here
   ("Layer3" 0) ;<- fill here
   ("Layer4" 0) ;<- fill here
 ); list
); setq *MyCountLyrs*

(defun C:test nil
 (alert
   (apply 'strcat
     (cons "Layer Statistics\n"
       (mapcar 
         (function 
           (lambda ( x / SS )
             (strcat "\n " (car x) "\tCount: " (itoa (if (setq SS (ssget "_X" (list (cons 8 (car x))))) (+ (cadr x) (sslength SS)) 0)))
           )
         )
         *MyCountLyrs*
       )
     )
   )
 )
 (princ)
); defun

Link to comment
Share on other sites

Maybe post your drawing. In the meantime, give this a try:

(defun c:foo (/ i p1 p2 p3 s)
 (setq    i (cond    ((mapcar 'cadr (ssnamex (setq s (ssget "_x" '((0 . "line"))))))
        (1+ (apply 'max
               (mapcar '(lambda (x) (fix (atof (cdr (assoc 8 (entget x))))))
                   (mapcar 'cadr (ssnamex s))
               )
            )
        )
       )
       (1)
     )
 )
 (while
   (progn
     (while (and (or (setq p1 p3) (setq p1 (getpoint "\nSpecify first point: ")))
         (setq p2 (getpoint p1 "\nSpecify next point: "))
        )
   (setq p3 nil)
   (if (entmakex (list '(0 . "line")
               (cons 10 p1)
               (cons 11 p2)
               (cons 8 (itoa i))
               (cons 62
                 (if (= 0 (rem i 255))
                   1
                   (rem i 255)
                 )
               )
             )
       )
     (princ (strcat "\nLine created on layer [" (itoa i) "]"))
   )
     )
     (if
   (setq p3 (getpoint (strcat "\nSpecify first point for next layer [" (itoa (1+ i)) "]: ")))
    (setq i (1+ i))
     )
   )
 )
 (princ)
)

 

 

wow! almost sir. the layer is not right...

if i made 2 lines on layer 1 the next layer should be 3, if I make 5 lines on layer 3 the next layer should be 7... and so on

 

 

 

 

here is a 2nd sample map...

this is the first lisp i made. you will see that the layer is individual...

it sould be like the blue texts i put.. my layer name is supposed to be 0, 2, 5, 12, 16, 20, 21, 23......

thus i tried asking for help... because i know you guys could come up a better solution than i can.

EL1020.dwg

Link to comment
Share on other sites

Not sure if I made a mistake but I drew multiple lines on one layer then incremented.

 

Oh just found bug need to put numero+1 in a different spot I create 2 5 9 12 etc

 

Yeah I am 12 hours out of sync but would appreciate any comments.

Link to comment
Share on other sites

wow! almost sir. the layer is not right...

if i made 2 lines on layer 1 the next layer should be 3, if I make 5 lines on layer 3 the next layer should be 7... and so on

...

I updated the code above. Give it a try.

Link to comment
Share on other sites

This is a pline but the same with Line, replaces the need for howmany.

 

; create pline by picking points press enter when finished
(command "_pline")
(while (= (getvar "cmdactive") 1 ) (command pause)
)

 

My attempt others I am sure will provide something as well.

(defun laychk (lay  / )
(if (not (tblsearch  "LAYER" (itoa lay)))
(command "_layer" "m" (itoa lay) "")
)
)
(defun c:testes ()
(if (/= numero nil)
(setvar 'clayer (itoa numero))
(progn
(setq numero (getint "Enter a number"))
(laychk numero)
)
)
(setq continue "Y")         
(while (=  continue "Y")
(command "_pline")
(while (= (getvar "cmdactive") 1 ) (command pause)
)
(setq numero (+ numero 1))
(laychk numero)
(if (= (setq continue (Getstring "Press <Cr> to continue any key to exit")) "")
(setq continue "Y")(setq continue "N"))
)
(princ)
)
(c:testes)

 

 

Thank you sir ill try to use this for polylines! thank you so much!

 

Maybe post your drawing. In the meantime, give this a try:

(defun c:foo (/ i n p1 p2 p3 s)
 (setq	i (cond	((mapcar 'cadr (ssnamex (setq s (ssget "_x" '((0 . "line"))))))
	 (1+ (apply 'max
		    (mapcar '(lambda (x) (fix (atof (cdr (assoc 8 (entget x))))))
			    (mapcar 'cadr (ssnamex s))
		    )
	     )
	 )
	)
	(1)
  )
 )
 (while
   (progn
     (setq n 0)
     (while (and (or (setq p1 p3) (setq p1 (getpoint "\nSpecify first point: ")))
	  (setq p2 (getpoint p1 "\nSpecify next point: "))
     )
(setq p3 nil)
(and (entmakex (list '(0 . "line")
		     (cons 10 p1)
		     (cons 11 p2)
		     (cons 8 (itoa i))
		     (cons 62
			   (if (= 0 (rem i 255))
			     1
			     (rem i 255)
			   )
		     )
	       )
     )
     (setq n (1+ n))
     (princ (strcat "\nLine created on layer [" (itoa i) "]"))
)
     )
     (if
(setq p3 (getpoint (strcat "\nSpecify first point for next layer [" (itoa (+ n i)) "]: ")))
 (setq i (+ n i))
     )
   )
 )
 (princ)
)

 

wow this is what my problem was.. thank you you solved it :) i will try to use this for my routine

Link to comment
Share on other sites

Glad to help out :) .. BTW you should copy the code above again .. had an error.

 

  (setq	i (cond	([color="red"](mapcar 'cadr (ssnamex (setq s (ssget "_x" '((0 . "line"))))))[/color] This will bomb if no selection is found.
	 (1+ (apply 'max
		    (mapcar '(lambda (x) (fix (atof (cdr (assoc 8 (entget x))))))
			    (mapcar 'cadr (ssnamex s))
		    )
	     )
	 )
	)
	(1)
  )
 )

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