Help with Layers, TBLSearch, a
Hello all,I need some assistance with the following code. I am trying to make a LISP routine that:
1. Verifies if certain layers are present and adds them if not
2. Adds/changes linetype of said layers
3. Adds/changes color of said layers
4. Adds/changes lineweight of said layers
The problem I am having is that
(TBLSEARCH "LAYER" layer_name) is not accepting strings from the lists I've made. It returns
; error: bad argument type: stringp ("T-Center")
Ideally I'd be reading the layer data from cells in Excel, but I've not savvy enough to do that yet. So I am starting with this.
Other refinements are more than welcome.
Thanks for any help.
(DEFUN c:tseat2 (/ layer_list layer_color_list current_layer flayer_color_listlayer_set linetype_name layer_name layer item layer_linetype_list flayer_linetype_list layer_lineweight_list flayer_lineweight_list ) (SETQ layer_list (LIST '("T-Center") '("T-Seat") ) ; end list ) ; end setq (SETQ layer_linetype_list (LIST '("T-Center" "center") '("T-Seat" "continuous") ) ; end list ) ; end setq(SETQ layer_color_list (LIST '("T-Center" 2) '("T-Seat" 1) ) ; end list ) ; end setq (SETQ layer_lineweight_list (LIST '("T-Center" "0.13") '("T-Seat" "0.35") ) ; end list ) ; end setq (VL-LOAD-COM) ;; Check to see if layer exists, if not create it (FOREACH layer_name layer_list (IF (NOT (TBLSEARCH "LAYER" layer_name)) (PROGN (SETQ layer (VLA-ADD (VLA-GET-LAYERS (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT) ) ) layer_name ) );End setq ) );End if );End foreach ;; Loading Linetypes (FOREACH linetype_name layer_linetype_list (IF (NOT (TBLSEARCH "LTYPE" linetype_name)) (VLA-LOAD (VLA-GET-LINETYPES (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT) ) ) linetype_name "acad.lin" ) );End if );End foreach ;; Set Layer Colors (FOREACH layer layer_color_list (IF (NOT (VL-CATCH-ALL-ERROR-P (SETQ current_layer (VL-CATCH-ALL-APPLY 'VLA-ITEM (LIST (VLA-GET-LAYERS (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT) ) ) (CAR layer) );End List ) );End Setq ) );End If (PROGN (VLA-PUT-COLOR current_layer (CADR layer)) (SETQ flayer_color_list (LIST (CONS 8 (VLA-GET-NAME current_layer))) );End Setq (SETQ flayer_linetype_list (LIST (CONS 8 (VLA-GET-NAME current_layer))) );End Setq (SETQ flayer_lineweight_list (LIST (CONS 8 (VLA-GET-NAME current_layer))) );End Setq (IF (SETQ layer_set (SSGET "_X" flayer_color_list)) (PROGN (FOREACH item (MAPCAR 'VLAX-ENAME->VLA-OBJECT (VL-REMOVE-IF 'LISTP (MAPCAR 'CADR (SSNAMEX layer_set)) ) ) (VLA-PUT-COLOR item ACBYLAYER) ) ; end foreach ) ; end if (IF (SETQ layer_set (SSGET "_X" flayer_linetype_list)) (PROGN (FOREACH item (MAPCAR 'VLAX-ENAME->VLA-OBJECT (VL-REMOVE-IF 'LISTP (MAPCAR 'CADR (SSNAMEX layer_set)) ) ) (VLA-PUT-LINETYPE item ACBYLAYER) ) ; end foreach ) ; end if (IF (SETQ layer_set (SSGET "_X" flayer_lineweight_list)) (PROGN (FOREACH item (MAPCAR 'VLAX-ENAME->VLA-OBJECT (VL-REMOVE-IF 'LISTP (MAPCAR 'CADR (SSNAMEX layer_set)) ) ) (VLA-PUT-LINEWEIGHT item ACBYLAYER) ) ; end foreach ) ; end if ) ; end progn ) ; end progn ) ; end if ) ; end foreach (PRINC)) ; end Sorry I haven't written in a while and i didnt get a chance to look over your code but it seems like you are trying to input a list where a string should go.
; error: bad argument type: stringp ("T-Center")
("T-Center") should be "T-Center" Indeed it is acting as though I am passing it a list,instead of a string, but its part of a FOREACH command, so it should be parsing the list entry by entry and passing it to the TBLSEARCH command. That's my dilemma.
(FOREACH layer_name layer_list
(IF (NOT (TBLSEARCH "LAYER" layer_name))
You are making a list of lists here,not a string list
(("T-Center"))
where you would want
("T-Center")
(SETQ layer_list; (LIST '("T-Center") '("T-Seat"); ) ; end list ) ; end setq
HTH-David I've got a good handle on this now. Thanks everyone. The excel portion isn't that hard. I'm not sure to what extent you would be using it but the basics are easy.
(defun basics (vscaleav / thefilename) (vl-load-com) ; This makes it possible to use vl commands (setq thefilename "c://filepath.xls") ; This sets the file you want to open (setq excapp (vlax-get-or-create-object "Excel.Application")) ; This sets the excel application; Create VBA objects from data (global) (if excapp (setq wCells (vlax-get (vlax-get-property (vlax-get (vla-open (vlax-get excapp "Workbooks") thefilename) "Sheets") "Item" 1) "Cells")); this brings you down to the cell level from here everything is easy ); /If (vlax-put-property wCells "Item" 15 1 vscaleav); this code places a variable "vscaleav" in row 15 column 1 into excel. I you used vlax-get-property it would extract information from that row or cell (princ) ); /Defun
If you have a good handle on how lisp works then you should be able to write something basic from here.
页:
[1]