luiscarneirorm Posted August 29, 2011 Author Share Posted August 29, 2011 Your English is good. Are the ENTITIES (the objects drawn in modelspace) assigned an individual lineweight, or are they all set to ByLayer, and the LAYER is assigned a lineweight? this is the biggest problem, because some are an individual lineweight and other are bylayer. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 29, 2011 Share Posted August 29, 2011 Maybe something like this as an example: (defun c:test ( / df ls lw ) (while (and (setq lw (getreal "\nSpecify LWeight: ")) (or (< lw 0.0) (< 2.11 lw) ) ) (princ "\nLineweight must be 0.0 <= x <= 2.11") ) (if lw (progn (setq lw (fix (* 100 lw))) (while (setq df (tblnext "LAYER" (null df))) (if (= lw (cdr (assoc 370 (entget (tblobjname "LAYER" (cdr (assoc 2 df))))))) (setq ls (cons "," (cons (cdr (assoc 2 df)) ls))) ) ) (sssetfirst nil (ssget "_X" (cons (cons 410 (if (= 1 (getvar 'CVPORT)) (getvar 'CTAB) "Model")) (if ls (list (cons -4 "<OR") (cons 370 lw) (cons 8 (apply 'strcat (cdr ls))) (cons -4 "OR>") ) (list (cons 370 lw)) ) ) ) ) ) ) ) Quote Link to comment Share on other sites More sharing options...
luiscarneirorm Posted August 29, 2011 Author Share Posted August 29, 2011 Maybe something like this as an example: (defun c:test ( / df ls lw ) (while (and (setq lw (getreal "\nSpecify LWeight: ")) (or (< lw 0.0) (< 2.11 lw) ) ) (princ "\nLineweight must be 0.0 <= x <= 2.11") ) (if lw (progn (setq lw (fix (* 100 lw))) (while (setq df (tblnext "LAYER" (null df))) (if (= lw (cdr (assoc 370 (entget (tblobjname "LAYER" (cdr (assoc 2 df))))))) (setq ls (cons "," (cons (cdr (assoc 2 df)) ls))) ) ) (sssetfirst nil (ssget "_X" (cons (cons 410 (if (= 1 (getvar 'CVPORT)) (getvar 'CTAB) "Model")) (if ls (list (cons -4 "<OR") (cons 370 lw) (cons 8 (apply 'strcat (cdr ls))) (cons -4 "OR>") ) (list (cons 370 lw)) ) ) ) ) ) ) ) Thanks, it works. The only difference is that I wanted to select entities with greater than linewight=0.2 for example, but this is already very very useful. I think with a little research I can adjust myself to my purpose Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 29, 2011 Share Posted August 29, 2011 The only difference is that I wanted to select entities with greater than linewight=0.2 for example, but this is already very very useful. I think with a little research I can adjust myself to my purpose Sure, this was just an example. Quote Link to comment Share on other sites More sharing options...
luiscarneirorm Posted August 29, 2011 Author Share Posted August 29, 2011 One more thing, it is possible to translate a macro to a Lisp function? I have this macro that calls some functions, but if one gives the error, the macro stops. overkill all [color=red]F7[/color] -LAYER NEW CHEIO COLOR 1 CHEIO SET CHEIO [color=red]HB[/color] ALL [color=red]E2PO[/color] ALL [color=red]F5[/color] ALL [color=red]TROCALL[/color] [color=red]F5[/color] ALL TXTEXP -LAYER OFF CHEIO Y PURGE ALL N -LAYER NEW A01-20 COLOR 1 A01-20 -LAYER NEW A02-20 COLOR 2 A02-20 -LAYER NEW A03-20 COLOR 3 A03-20 -LAYER NEW A04-20 COLOR 4 A04-20 -LAYER NEW A05-20 COLOR 5 A05-20 -LAYER NEW A06-20 COLOR 6 A06-20 -LAYER NEW A07-20 COLOR 8 A07-20 -LAYER NEW A08-20 COLOR 11 A08-20 -LAYER NEW A09-20 COLOR 25 A09-20 -LAYER NEW L01 COLOR 1 L01 L DASHED L01 -LAYER NEW L02 COLOR 2 L02 L DASHED L02 -LAYER NEW L03 COLOR 3 L03 L DASHED L03 -LAYER NEW L04 COLOR 4 L04 L DASHED L04 -LAYER NEW L05 COLOR 5 L05 L DASHED L05 -LAYER NEW L06 COLOR 6 L06 L DASHED L06 -LAYER NEW L07 COLOR 8 L07 L DASHED L07 -LAYER NEW L08 COLOR 36 L08 L DASHED L08 -LAYER NEW L09 COLOR 21 L09 L DASHED L09 -LAYER NEW L09 COLOR 75 L09 L DASHED L09 -LAYER NEW L1W50 COLOR 1 L1W50 L DASHED L1W50 -LAYER NEW L2W50 COLOR 2 L2W50 L DASHED L2W50 -LAYER NEW L3W50 COLOR 3 L3W50 L DASHED L3W50 -LAYER L DASHED 0 SET 0 -LAYER OFF 0 Y [color=red]F4[/color] ALL FLATTEN N [color=red]TROCALLL[/color] red funccions it's lisp funccions sorry this is very confusing, but as I said I am new to AutoLISP and my inglish is not very good (translator) Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted August 29, 2011 Share Posted August 29, 2011 For commands inside *.lsp, you can use : (command "_.commandname" "commandfunction1-cf1" "cf2" "cf3" ... "") witch will execute that command and always return after execution : nil, or (vl-cmdf "_.commandname" "commandfunction1-cf1" "cf2" "cf3" ... "") witch will execute that command and always return before execution : T For calling other *.lsp previously loaded into CAD memory, you can use : - for command functions (defun c:functionname ( arg1 arg2 ... / var1 var2 ... ) ... ) calling from your *.lsp : (c:functionname arg1 arg2 ...) - for non command functions (defun functionname ( arg1 arg2 ... / var1 var2 ... ) ... ) calling from your *.lsp : (functionname arg1 arg2 ...) M.R. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 29, 2011 Share Posted August 29, 2011 Hello Marko, Welcome to CADTutor - I know you're not new to LISP, but.... SLW get's angry when you forget to use , and you wouldn't like him when he's angry. Quote Link to comment Share on other sites More sharing options...
luiscarneirorm Posted August 29, 2011 Author Share Posted August 29, 2011 For commands inside *.lsp, you can use : (command "_.commandname" "commandfunction1-cf1" "cf2" "cf3" ... "") witch will execute that command and always return after execution : nil, or (vl-cmdf "_.commandname" "commandfunction1-cf1" "cf2" "cf3" ... "") witch will execute that command and always return before execution : T For calling other *.lsp previously loaded into CAD memory, you can use : - for command functions (defun c:functionname ( arg1 arg2 ... / var1 var2 ... ) ... ) calling from your *.lsp : (c:functionname arg1 arg2 ...) - for non command functions (defun functionname ( arg1 arg2 ... / var1 var2 ... ) ... ) calling from your *.lsp : (functionname arg1 arg2 ...) M.R. sorry but it is very confusing to me. I made this script works perfectly, my problem is for example: the script selects all "mtext" and explode them, but if there is no "mtext" gives error and does not perform any further function. Command: F5 Select objects: ALL 0 found Select objects: No previous coordinate system saved. Error: Function cancelled No previous coordinate system saved. ; error: An error has occurred inside the *error* functionFunction cancelled Can i use "IF" in scripts??? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 29, 2011 Share Posted August 29, 2011 Please post the code for F5. Edit: Can i use "IF" in scripts??? You can use LISP in scripts, or your script can call a LISP routine (as is shown above). Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 29, 2011 Share Posted August 29, 2011 hello marko, slw get's angry when you forget to use , and you wouldn't like him when he's angry. Agreed Quote Link to comment Share on other sites More sharing options...
luiscarneirorm Posted August 29, 2011 Author Share Posted August 29, 2011 ;Seleciona todos os textos (defun c:f5(/ cSet) (setq cSet(ssget '((0 . "TEXT,MTEXT")) ); end ssget ); end setq (if cSet (progn (princ(strcat "\n" (itoa(sslength cSet)) " found.")) (sssetfirst nil cSet) ); end progn (princ "\nNothing found. ") ); end if (princ) ); end of c:f5 this is the f5 funccion. That works perfectly, my problem is when there is no text in the drawing. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 29, 2011 Share Posted August 29, 2011 While I would personally write the F5 function differently, it (F5) does not *appear* to be the cause of the error you posted: Command: F5 Select objects: [color=red]<EndF5>[/color] ALL [color=red]<BeginTROCALL>[/color] 0 found Select objects: No previous coordinate system saved. Error: Function cancelled No previous coordinate system saved. ; error: An error has occurred inside the *error* functionFunction cancelled Perhaps, if you were to outline exactly what it is you are trying to do (in entirety), we might be able to better suggest options, rather than addressing one tiny step at a time? Quote Link to comment Share on other sites More sharing options...
luiscarneirorm Posted August 29, 2011 Author Share Posted August 29, 2011 My problem is when there is no text in the drawing, because if there is text the script continues to the next function and explode the text and change it to a new layer and performs other functions, but no text when the script stops running. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 29, 2011 Share Posted August 29, 2011 (edited) Then you need to revise your LISP. For example, instead of this (in your script): [color=red]F5[/color] ALL [color=red]TROCALL[/color] ... Use this as your F5 LISP: (defun c:F5 ( / ss) (if (setq ss (ssget [color=red]"_x"[/color] '((0 . "TEXT,MTEXT")))) (progn (princ (strcat "\n" (itoa (sslength ss)) " found.")) (sssetfirst nil ss)) (princ "\nNothing found. ")) (princ)) ... This way, if there are no Text, or MText, then nothing is selected. If you still have an error as a result of nothing being selected at the F5 step, then that means the next step(s) (i.e., TROCALL LISP), are not written correctly. Hope this helps! Edited August 29, 2011 by BlackBox I ALWAYS see the typos AFTER I hit submit! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 29, 2011 Share Posted August 29, 2011 Renderman . Please recheck the first name of the variable . Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 29, 2011 Share Posted August 29, 2011 Renderman . Please recheck the first name of the variable . I use "ss" as habit, meant to use the OP's variable name. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 29, 2011 Share Posted August 29, 2011 I use "ss" as habit, meant to use the OP's variable name. No worries , it's my habit too . Quote Link to comment Share on other sites More sharing options...
luiscarneirorm Posted August 29, 2011 Author Share Posted August 29, 2011 My biggest problem is I can not even explain ... My script is working well, the only thing I'm missing is to prevent a case of not having any text in the drawing, the the script has to jump to the function "-layer off cheio y" [color=red][color=black](...)[/color] f5[/color] all [color=red] trocall[/color] [color=red] f5[/color] all txtexp -layer off cheio y (...) Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 29, 2011 Share Posted August 29, 2011 luiscarneirorm, In order to accomplish this, you need to incorporate LISP. As an example, if you were to use your script to call a *new* LISP routine. Script: (load "NewLISP.lsp") NewLISP NewLISP.lsp: (defun c:NewLISP () (vl-load-com) ((lambda (acDoc / _makelayer _LayerItem ss) (defun _makelayer (name color ltype lnwt) ;; Lee Mac, 2011 ((lambda (_function) (_function (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 name) (cons 70 0) (cons 62 color) (cons 6 ltype) (cons 370 lnwt)))) (if (tblsearch "LAYER" name) (lambda (data) (entmod (cons (cons -1 (tblobjname "LAYER" name)) data))) entmakex))) (defun _LayerItem (layerName) (if (tblsearch "layer" layerNmae) (vla-item (vla-get-layers acDoc) layerName))) (foreach lsp '("overkillsup" "overkill") (vl-catch-all-apply 'load (list lsp))) (acet-overkill2 (list (ssget "_x") 0.000001 nil nil nil nil)) [color=red];; <- c:F7 here[/color] (_makelayer "CHEIO" 1 "Continuous" -3) [color=red];; <- c:HB here ;; <- c:E2PO here ;; <- c:F5 here ;; <- c:TROCALL here ;; <- INSTEAD of c:F5 here:[/color] (if (setq ss (ssget "_x" '((0 . "MTEXT,TEXT")))) (vla-put-layeron (_LayerItem "CHEIO") :vlax-false)) (vla-purgeall acDoc) (foreach lay '(("A01-20" 1 "Continuous" -3) ("A02-20" 2 "Continuous" -3) ("A03-20" 3 "Continuous" -3) ("A04-20" 4 "Continuous" -3) ("A05-20" 5 "Continuous" -3) ("A06-20" 6 "Continuous" -3) ("A07-20" 8 "Continuous" -3) ("A08-20" 11 "Continuous" -3) ("A09-20" 25 "Continuous" -3) ("L01" 1 "Dashed" -3) ("L02" 2 "Dashed" -3) ("L03" 3 "Dashed" -3) ("L04" 4 "Dashed" -3) ("L05" 5 "Dashed" -3) ("L06" 6 "Dashed" -3) ("L07" 8 "Dashed" -3) ("L08" 36 "Dashed" -3) [color=red];;("L09" 21 "Dashed" -3) ;<- duplicate?[/color] ("L09" 75 "Dashed" -3) ("L1W50" 1 "Dashed" -3) ("L2W50" 2 "Dashed" -3) ("L3W50" 2 "Dashed" -3)) (vl-catch-all-apply '_makelayer lay)) (vla-put-layeron (_layerItem "0") :vlax-false) [color=red];; <- c:F4 here[/color] ) (vla-get-activedocument (vlax-get-acad-object))) (princ)) ** Note - This is the best *example* I can provide, given that I do not know what code you are including in the functions in red. I hope this helps! Quote Link to comment Share on other sites More sharing options...
luiscarneirorm Posted August 30, 2011 Author Share Posted August 30, 2011 Maybe something like this as an example: (defun c:test ( / df ls lw ) (while (and (setq lw (getreal "\nSpecify LWeight: ")) (or (< lw 0.0) (< 2.11 lw) ) ) (princ "\nLineweight must be 0.0 <= x <= 2.11") ) (if lw (progn (setq lw (fix (* 100 lw))) (while (setq df (tblnext "LAYER" (null df))) (if (= lw (cdr (assoc 370 (entget (tblobjname "LAYER" (cdr (assoc 2 df))))))) (setq ls (cons "," (cons (cdr (assoc 2 df)) ls))) ) ) (sssetfirst nil (ssget "_X" (cons (cons 410 (if (= 1 (getvar 'CVPORT)) (getvar 'CTAB) "Model")) (if ls (list (cons -4 "<OR") (cons 370 lw) (cons 8 (apply 'strcat (cdr ls))) (cons -4 "OR>") ) (list (cons 370 lw)) ) ) ) ) ) ) ) Lee Mac, or someone else, can you help me to change this function to select all entities with linetipe are not continuous? And as in this case, I also have some entities with linetipe bylayer, and others with individual linetype. I think it should be simple (adapt this exemple) but for me it is still very confusing the lisp linguage, and the dxf codes Thanks for the help. I am enjoying this language, but it's hard for me, I'm accustomed to program in simple language. P.S.: RenderMan, thanks for your post, but I think I'll leave that for later (it's hard for me, for now:cry:) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.