Jump to content

Recommended Posts

Posted

I need to overwrite layers from so many drawings. I thought it could be solved with this code:

 

(setq layers (list "005_DIMENSION" "off" "thaw" "unlock" "255" "255" "255" "Continuous" "-3" "CHBL_01" "dimensions"))
(entmake (list (cons 0 "LAYER")
          (cons 100 "AcDbSymbolTableRecord")
          (cons 100 "AcDbLayerTableRecord")
          (cons 2 (car layers))
          (cons 70 0)
    )
)
(setq layers (cdr layers))
(if (= (car layers) "on")
 (setq test ':vlax-true)
 (setq test ':vlax-false)
)
(vla-put-layeron
 (vlax-ename->vla-object
   (tblobjname "LAYER" (car layers))
 )
 (princ test)
)

 

The proble at the end is that I can not /read/add the value from a symbol in my lisp (it is called test)

 

Can anybody help me please?

Posted

You should check this line:

 (tblobjname "LAYER" (car layers))

Please pay attention that you already removed above the name of layer from list:

 (setq layers (cdr layers))

 

I suggest looking for NTH function to access items from list. Or even better to build a pseudo-dictionary (list of dotted pairs) instead to don’t rely on items position.

Posted
I need to overwrite layers from so many drawings. I thought it could be solved with this code:

 

.....
(setq layers (cdr layers))
(if (= (car layers) "on")
(setq test ':vlax-true)
(setq test ':vlax-false)
).....

Can anybody help me please?

 

BY overwrite you mean Turn the layer off if it is on and vice versa?

 

Use foreach function, that way you dont need (car layers) and (cdr layers) to track the layer names and current status.

Posted

Maybe another way is to use a script and just use autocad commands

 

eg _layer m C layer1 1 LT layer1 dashed

_layer m C layer2 1 LT layer2 continuous

 

use the m for make this way it changes the layer if it exists if not adds it

 

This will change layer settings you just need a master list of your layer names you can also do rename as well you can also do lisp in a script say an IF layer exsit do something. I suggest this as would be easier than creating great long layer LIST statements. Also other way is to use the same _layer statement in a lisp same as the entmake but dont have to worry if you leave a setting out, but read a text file line by line just replace responces required from the file. Set it up in say Excel and export a CSV file theres examples how to do this here. I used also a fixed length txt file so know how many characters = layername colour number LT and so on. Using a txt file means you can add change or remove and just run again simply.

Posted

Thank you all very much. Still not solved my problem because I have not been able to add a description to each layer through autolisp? that is the only reason I was trying to use this program:

 

(setq layers (list "005_DIMENSION"           "off"
          "thaw"     "unlock"      "255"
          "255"     "255"           "Continuous"
          "-3"         "TEST_01"     "dimensions FOR ALL DRAWINGS"
         )
)
(entmake (list (cons 0 "LAYER")
          (cons 100 "AcDbSymbolTableRecord")
          (cons 100 "AcDbLayerTableRecord")
          (cons 2 (car layers))
          (cons 70 0)
    )
)
(setq layers (cdr layers))
(if (= (car layers) "on")
 (setq test ':vlax-true)    ;;;;;;here I am trying to add the value from a sym to a variable
 (setq test ':vlax-false)    ;;;;;;here I am trying to add the value from a sym to a variable
)
(vla-put-layeron
 (vlax-ename->vla-object
   (tblobjname "LAYER" (car layers))
 )
 (eval (vl-symbol-value test))
)
(vla-put-layeron
 (vlax-ename->vla-object
   (tblobjname "LAYER" (car layers))
 )
 (eval test)            ;;;;;;here I want to read the variable's value from the symbol
)

 

The list I create at the beginning, is just a placeholder, because I am actually reading those values from a CSV file which contains all layer & conditions list. The main problem as I said is that I cannot add a description.

 

Thanks all again

Posted

Yes MSasu, I know I took the layer name out, that's exactly what I wanted because I read now the second entity of the list which in my CSV file is "off" and that's the value I want to add to the layer and so on...

At the end I have configured the CSV file with these values at the top:

 

"name;on/off;freeze/thaw;lock/unlock;r;g;b;linetype;lineweight;plotstyle;description"

 

for them to be read each line so I can overwrite current layer values in every drawing with the ones I have in the CSV file.

 

Thanks again

Posted
I know I took the layer name out, that's exactly what I wanted

That OK for me, but then you should find a different way to supply the layer name to TBLOBJNAME function. Excerpt from your code :

(tblobjname "LAYER" [color=red](car layers)[/color])

Posted

I cannot make this work, any idea?

 

(setq test ':vlax-false)
)
(vla-put-layeron
 (vlax-ename->vla-object
   (tblobjname "LAYER" "0")
 )
 (eval test) ;;;;;; Here it is the mistake
)

 

If I put it this way it works

(vla-put-layeron
 (vlax-ename->vla-object
   (tblobjname "LAYER" "0")
 )
 :vlax-false ;;;;;; I cannot make this work, any idea?
)

 

That is my problem to be solved.

 

Thanks again in advance

Sergio

Posted

I finally solved it like this... thanks anyway

 

(defun tttt () ':vlax-false)
(vla-put-layeron
 (vlax-ename->vla-object
   (tblobjname "LAYER" "0")
 )
 (tttt)
)

Posted

MSasu, thanks a lot, I was completely wrong since I was not taking the name from the layer and I tried to turn it off the layer "off". This is working:

(setq layers (list "005_DIMENSION"           "off"
          "thaw"     "unlock"      "255"
          "255"     "255"           "Continuous"
          "-3"         "TEST_01"     "dimensions FOR ALL DRAWINGS"
         )
)
(entmake (list (cons 0 "LAYER")
          (cons 100 "AcDbSymbolTableRecord")
          (cons 100 "AcDbLayerTableRecord")
          (cons 2 (car layers))
          (cons 70 0)
    )
)
(setq 1st_value (car layers))
(setq layers (cdr layers))
(if (= (car layers) "on")
 (setq test ':vlax-true)
 (setq test ':vlax-false)
)
(vla-put-layeron
 (vlax-ename->vla-object
   (tblobjname "LAYER" 1st_value)
 )
 (eval test)
)

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