Lee Mac Posted August 30, 2011 Posted August 30, 2011 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. Here is a quick modification: (defun _selectlinetype ( lt / df ls ) (while (setq df (tblnext "LAYER" (null df))) (if (eq lt (cdr (assoc 6 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 6 lt) (cons 8 (apply 'strcat (cdr ls))) (cons -4 "OR>") ) (list (cons 6 lt)) ) ) ) ) ) To be called with the name of the linetype, e.g: (_SelectLinetype "HIDDEN") I shall leave the task of adding a user prompt (if necessary) to you. A reference for the DXF group codes can be found here. Quote
BlackBox Posted August 30, 2011 Posted August 30, 2011 P.S.: RenderMan, thanks for your post, but I think I'll leave that for later (it's hard for me, for now:cry:) You're welcome, luiscarneirorm. I'm sorry that my post was not able to help you more. Quote
luiscarneirorm Posted August 30, 2011 Author Posted August 30, 2011 Here is a quick modification: (defun _selectlinetype ( lt / df ls ) (while (setq df (tblnext "LAYER" (null df))) (if (eq lt (cdr (assoc 6 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 6 lt) (cons 8 (apply 'strcat (cdr ls))) (cons -4 "OR>") ) (list (cons 6 lt)) ) ) ) ) ) To be called with the name of the linetype, e.g: (_SelectLinetype "HIDDEN") I shall leave the task of adding a user prompt (if necessary) to you. A reference for the DXF group codes can be found here. I want to select all entities with linetype not continuous. I tried to change this way: (...) (if ([b]not[/b] eq lt (cdr (assoc 6 df))) (...) but as I feared is not so simple Quote
BlackBox Posted August 30, 2011 Posted August 30, 2011 Perhaps, replacing: (cons 6 lt) ... With this: (cons 6 (strcat "~" lt)) Quote
Lee Mac Posted August 30, 2011 Posted August 30, 2011 I want to select all entities with linetype not continuous. I tried to change this way: (...) (if ([b]not[/b] eq lt (cdr (assoc 6 df))) (...) but as I feared is not so simple Close, but there are a few extra parts to add: (defun _selectifnotlinetype ( lt / df ls ) [color=red](setq lt (strcase lt))[/color] [color=green];; To remove case-sensitivity[/color] (while (setq df (tblnext "LAYER" (null df))) (if [color=red](not[/color] (eq lt [color=red](strcase[/color] (cdr (assoc 6 df))[color=red])[/color])[color=red])[/color] (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 6 [color=red](strcat "~" [color=black]lt[/color])[/color]) (cons 8 (apply 'strcat (cdr ls))) (cons -4 "OR>") ) (list (cons 6 [color=red](strcat "~"[/color] lt[color=red])[/color])) ) ) ) ) ) (_selectifnotlinetype "Continuous") Quote
luiscarneirorm Posted August 30, 2011 Author Posted August 30, 2011 Perhaps, replacing: (cons 6 lt) ... With this: (cons 6 (strcat "~" lt)) this way also selects the entities that are "bylayer (continuous)" And i have exactly the same problem with your code Lee Mac Quote
luiscarneirorm Posted August 30, 2011 Author Posted August 30, 2011 Lee, i change your code to: (defun _selectifnotlinetype ( lt / df ls ) (setq lt (strcase lt)) ;; To remove case-sensitivity (while (setq df (tblnext "LAYER" (null df))) (if (not (eq lt (strcase (cdr (assoc 6 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 6 (strcat lt)) (cons 8 (apply 'strcat (cdr ls))) (cons -4 "OR>") ) (list (cons 6 (strcat lt))) ) ) ) ) ) and the result is already closer to what I meant, but still selects some entities are on layer with linetype dashed, but have the individual linetype defined as Continuous. I did just the opposite of what RenderMan tell me before: i replace (cons 6 (strcat "~" lt)) with (cons 6 lt) P.S: I just now detected, but the function of post 22, happens the same thing, if the entities have a lineweight set individually, and not by layer, it is not selected:( Quote
Lee Mac Posted August 30, 2011 Posted August 30, 2011 P.S: I just now detected, but the function of post 22, happens the same thing, if the entities have a lineweight set individually, and not by layer, it is not selected:( Good catch, I had overlooked that Try this instead: (defun _selectifnotlinetype ( lt / df ls ) (setq lt (strcase lt)) ;; To remove case-sensitivity (while (setq df (tblnext "LAYER" (null df))) (if (not (eq lt (strcase (cdr (assoc 6 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 -4 "<AND") (cons 6 "ByLayer") (cons 8 (apply 'strcat (cdr ls))) (cons -4 "AND>") (cons -4 "<NOT") (cons 6 (strcat lt ",ByLayer")) (cons -4 "NOT>") (cons -4 "OR>") ) (list (cons -4 "<NOT") (cons 6 (strcat lt ",ByLayer")) (cons -4 "NOT>") ) ) ) ) ) ) (_selectifnotlinetype "Continuous") To correct post#22: (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 -4 "<AND") (cons 370 -1) (cons 8 (apply 'strcat (cdr ls))) (cons -4 "AND>") (cons 370 lw) (cons -4 "OR>") ) (list (cons 370 lw)) ) ) ) ) ) ) ) These ssget filter lists can be tricky at times... Quote
luiscarneirorm Posted August 30, 2011 Author Posted August 30, 2011 She's work perfectly Based on this I'll try to correct the other function Thank you very much Quote
luiscarneirorm Posted August 31, 2011 Author Posted August 31, 2011 (edited) Hi. i try to insert this code in the end off this function, to put the selected entities in the current layer. (defun c:espessura ( / df ls lw [color=red]e[/color] ) (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 -4 "<AND") (cons 370 -1) (cons 8 (apply 'strcat (cdr ls))) (cons -4 "AND>") (cons 370 lw) (cons -4 "OR>") ) (list (cons 370 lw)) ) ) ) ) ) ) [color=red](setq e (getvar "clayer")) (command "change" ls "" "prop" "layer" e "")[/color] ) but as I feared I did not succeed:( (the code in red is what I added) Command: espessura Specify LWeight: 0.4 change Select objects: Command: ESPESSURA Unknown command "ESPESSURA". Press F1 for help. Command: prop Unknown command "PROP". Press F1 for help. Command: layer Current layer: "0" Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck /Unlock/stAte/Description/rEconcile]: 0 Invalid option keyword. ; error: Function cancelled what am I doing wrong? P.S: Lee, this is your function, I just changed it's name Edited August 31, 2011 by luiscarneirorm Quote
Lee Mac Posted August 31, 2011 Posted August 31, 2011 what am I doing wrong? The variable 'ls' stores a list of strings, not a selection set as required by the 'chprop' command. I use the sssetfirst function to highlight the selection set returned by ssget, but if instead you wanted to use this selection set in the code, it would be easier to bound it to a variable, e.g.: (defun c:espessura ( / df en i ls lw ss ) (while (and (setq lw (getreal "\nSpecify LWeight: ")) (or (< lw 0.0) (< 2.11 lw) ) ) (princ "\nLineweight must be 0.0 <= x <= 2.11") ) (if (and 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))) ) ) (setq ss (ssget "_X" (cons (cons 410 (if (= 1 (getvar 'CVPORT)) (getvar 'CTAB) "Model")) (if ls (list (cons -4 "<OR") (cons -4 "<AND") (cons 370 -1) (cons 8 (apply 'strcat (cdr ls))) (cons -4 "AND>") (cons 370 lw) (cons -4 "OR>") ) (list (cons 370 lw)) ) ) ) ) ) ) (repeat (setq i (sslength ss)) (setq en (entget (ssname ss (setq i (1- i))))) (entmod (subst (cons 8 (getvar 'CLAYER)) (assoc 8 en) en)) ) ) (princ) ) In this way, I iterate through the Selection Set bound to the variable 'ss' using the repeat loop and modify the layer of each entity in the set. P.S: Lee, this is your function, I just changed it's name Not a problem Quote
luiscarneirorm Posted August 31, 2011 Author Posted August 31, 2011 Sorry, I try but can not solve by yourself. The functions works, but as I said before, if the entity is in a layer with lineweight less than 'lw' and this entity have your lineweight set individually greater than 'lw' it should be selected, but that does not happens:( But if on the contrary, if the entity is in a layer with lineweight greater than 'lw' and this entity have your lineweight set individually less than 'lw' it is not selected, the funccion works correctly in this case. Sorry if my explanation is too confusing Quote
Lee Mac Posted August 31, 2011 Posted August 31, 2011 The functions works, but as I said before, if the entity is in a layer with lineweight less than 'lw' and this entity have your lineweight set individually greater than 'lw' it should be selected, but that does not happens:( So you want to alter all entities with Lineweight less than the specified lineweight? I didn't notice your modification to this effect Quote
Lee Mac Posted August 31, 2011 Posted August 31, 2011 Try this modification: (defun c:espessura ( / df en i ls lw ss ) (while (and (setq lw (getreal "\nSpecify LWeight: ")) (or (< lw 0.0) (< 2.11 lw) ) ) (princ "\nLineweight must be 0.0 <= x <= 2.11") ) (if (and 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))) ) ) (setq ss (ssget "_X" (cons (cons 410 (if (= 1 (getvar 'CVPORT)) (getvar 'CTAB) "Model")) (if ls (list (cons -4 "<OR") (cons -4 "<AND") (cons 370 -1) (cons 8 (apply 'strcat (cdr ls))) (cons -4 "AND>") (cons -4 "<=") (cons 370 lw) (cons -4 "OR>") ) (list (cons -4 "<=") (cons 370 lw) ) ) ) ) ) ) ) (repeat (setq i (sslength ss)) (setq en (entget (ssname ss (setq i (1- i))))) (entmod (subst (cons 8 (getvar 'CLAYER)) (assoc 8 en) en)) ) ) (princ) ) Quote
luiscarneirorm Posted August 31, 2011 Author Posted August 31, 2011 Try this modification: (defun c:espessura ( / df en i ls lw ss ) (while (and (setq lw (getreal "\nSpecify LWeight: ")) (or (< lw 0.0) (< 2.11 lw) ) ) (princ "\nLineweight must be 0.0 <= x <= 2.11") ) (if (and 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))) ) ) (setq ss (ssget "_X" (cons (cons 410 (if (= 1 (getvar 'CVPORT)) (getvar 'CTAB) "Model")) (if ls (list (cons -4 "<OR") (cons -4 "<AND") (cons 370 -1) (cons 8 (apply 'strcat (cdr ls))) (cons -4 "AND>") (cons -4 "[color=black]<[/color]=") (cons 370 lw) (cons -4 "OR>") ) (list (cons -4 "[color=black]<[/color]=") (cons 370 lw) ) ) ) ) ) ) ) (repeat (setq i (sslength ss)) (setq en (entget (ssname ss (setq i (1- i))))) (entmod (subst (cons 8 (getvar 'CLAYER)) (assoc 8 en) en)) ) ) (princ) ) I finally able to solve a problem alone Lee Mac So you want to alter all entities with Lineweight less than the specified lineweight? i want to alter all entities with Lineweight greater than the specified lineweight. I just had to reverse 2 (defun c:espessura ( / df en i ls lw ss ) (while (and (setq lw (getreal "\nSpecify LWeight: ")) (or (< lw 0.0) (< 2.11 lw) ) ) (princ "\nLineweight must be 0.0 <= x <= 2.11") ) (if (and 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))) ) ) (setq ss (ssget "_X" (cons (cons 410 (if (= 1 (getvar 'CVPORT)) (getvar 'CTAB) "Model")) (if ls (list (cons -4 "<OR") (cons -4 "<AND") (cons 370 -1) (cons 8 (apply 'strcat (cdr ls))) (cons -4 "AND>") (cons -4 "[color=red][b]>[/b][/color]=") (cons 370 lw) (cons -4 "OR>") ) (list (cons -4 "[color=red][b]>[/b][/color]=") (cons 370 lw) ) ) ) ) ) ) ) (repeat (setq i (sslength ss)) (setq en (entget (ssname ss (setq i (1- i))))) (entmod (subst (cons 8 (getvar 'CLAYER)) (assoc 8 en) en)) ) ) (princ) ) Quote
Lee Mac Posted August 31, 2011 Posted August 31, 2011 Glad that you could solve it yourself I hope your learning of LISP has benefitted along the way Quote
luiscarneirorm Posted September 1, 2011 Author Posted September 1, 2011 Hello again... I am able to implement some functions for my work, without help , but now there is a problem that I can not solve:x I have a function to recreat the hatch boundaries. ( defun C:F8 (/ sset item i) (setq sset ( ssget "_X" '((0 . "HATCH"))) i -1 ) ( repeat (sslength sset) ( setq item (ssname sset (setq i (1+ i))) ) (command "._hatchedit" item "_B" "_P" "_Y") ) (princ) ) If I run only the function it works correctly, but I want to run it, after another function that I explode the blocks that also contain some hatch's (defun C:f7 (/ AllBlocks SolOnly ) (setvar "qaflags" 1) (setq AllBlocks (ssget "X" (list (cons 0 "INSERT")))) (while (/= AllBlocks nil) (progn (command "_.explode" AllBlocks "") (setq AllBlocks (ssget "X" (list (cons 0 "INSERT")))) );progn );while (setvar "qaflags" 0) (princ) ) the problem is: Command: f10 _.explode Select objects: 1 found Select objects: Command: _.explode Select objects: 1 found Select objects: Command: ._hatchedit Select hatch object: Use the Hatch Edit dialog box to modify gradients. Select hatch object: _B Specify first corner: _P Invalid window specification. ; error: Function cancelled the F10 function just call the F7 function and then the F8 function my goal is to change the hatch boundaries to a specified layer, and if it is possible, after this, delete the hatch's and the older original boundaries Quote
luiscarneirorm Posted September 1, 2011 Author Posted September 1, 2011 (edited) I've been searching and have tried to solve this problem in several ways, but I can not do it. I am suspicious that the problem stems from the F7 function, to change the variable value "qaflags" I am right? how can I solve this problem? Edit: I discovered that this was not my problem The problem is that after i explode the block, i get hatch's with invalid boundaries... Edited September 1, 2011 by luiscarneirorm Quote
luiscarneirorm Posted September 1, 2011 Author Posted September 1, 2011 I came up with a new problem the upper triangle is defined as a polyline with start segment with: 0 end segment with : 1.5 if i explode them, it becomes a simple line, but I need the outline is as below it is possible to do that??? poli.dxf Quote
luiscarneirorm Posted September 5, 2011 Author Posted September 5, 2011 Hi. Lee,i went through your site and found there just what I needed (Polyline Outline), but does not work properly, at least in my case:( You (or someone else) can take a look? I put the file in the previous post P.S: I've been testing with several polylines, and found that it works properly only with the start segment with, but the end segment with appears to me that ignores. Quote
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.