pttr Posted June 14, 2022 Posted June 14, 2022 Hi I´m back! This time I need to find what types of hatches I have placed in my model. This is my code currently but note that there will be more then one hatch and in different layers. (defun c:ph (/ rip1 rip2 hip bfind) ;Place Hatch (setq rip1 (list 0 0)) (setq rip2 (list 5 -5)) (setq hip (list 2 -2)) setq bfind (tblsearch "block" "B-B-U0013_L6")); This dosent work.... wanted to make IF statement after this. (command "RECTANG" rip1 rip2) ; places rectangle "boundry for Hatch (command "-Hatch" "LA" "B-B-U0013" "P" "S" hip "") ;Places hatch B-B-U0013but need boundrys (frame) and IP );Note future hatches may have transparasy (T) Any Ideas? Quote
pttr Posted June 14, 2022 Author Posted June 14, 2022 I just rememberd that I need the same function for a pline with special attributes Either search if the layer is placed in model or maybe search for plines with Scale, color and linetype. Both would work but I don´t know the solution. Hope you understand my crappy english Thanks! Quote
mhupp Posted June 14, 2022 Posted June 14, 2022 (edited) (if (setq blockss (ssget "_X" (list '(0 . "INSERT") '(2 . "B-B-U0013_L6") (cons 410 (getvar 'ctab))))) ;find all blocks on current tab (if (setq polyss (ssget "_X" (list '(0 . "polyline") '(8 . "layername") '(62 . #) (cons 410 (getvar 'ctab))))) ;update 8 w/ layer name and 62 w/ color number 62 doesn't need quotes. Use this to dump the dxf codes of entity's ;;----------------------------------------------------------------------------;; ;; Dump all DXF Group Data (defun C:DumpIt ( / ent) (while (setq ent (car (entsel "\nSelect Entity to Dump"))) (mapcar 'print (entget ent '( "*"))) ) (textscr) (princ) ) And this will show you the visual lisp data of entity's ;;----------------------------------------------------------------------------;; ;; Dump all methods and properties for selected objects (defun C:VDumpIt (/ ent) (while (setq ent (car (entsel "\nSelect Entity to Dump"))) (vlax-Dump-Object (vlax-Ename->Vla-Object ent) t) ) (textscr) (princ) ) Also the forums been around for a long time. try using the search also. Edited June 14, 2022 by mhupp update code Quote
mhupp Posted June 14, 2022 Posted June 14, 2022 (edited) (setq rip1 (list 0 0)) ;change to (setq rip1 (getpoint "\npick first point")) ;allows you to display msg ; forgot a " here (setq rip2 ... (command "RECTANG" rip1 rip2) ; places rectangle "boundry for Hatch or (command "_.RECTANG" pause pause) ; user pick points during the command. or (command "_.RECTANG" "0,-5" "5,0") ;usually you want to use the lower left & upper right corners. Edited June 14, 2022 by mhupp updated code Quote
pttr Posted June 14, 2022 Author Posted June 14, 2022 Hmm sorry but i can´t get any of the suggestions to work. I really liked the first lines of IF statements but when i tried them like this: (defun c:test (/ blockss) (if (setq blockss (ssget "_X" (list (0 . "HATCH") (2 . "B-B-U0013_L6") (cons 410 (getvar 'ctab)))) ;find all blocks on current tab (princ "Yes") ) ) (princ "test") ) I get bad syntax. If you have the time I could rly use something like this! Quote
Tharwat Posted June 14, 2022 Posted June 14, 2022 Hi, Your codes you posted into your last post did not work because you have one missing close bracket that should close the line of codes related to the variable blockss. This would list and print all found hatch patterns in current space : (defun c:Test (/ int sel ent lst pat) ;;----------------------------------------------------;; ;; Tharwat - Date : Jun.15.2020 ;; ;; website: https://autolispprograms.wordpress.com ;; ;; List all used Hatch patterns in current space. ;; ;;----------------------------------------------------;; (and (or (setq int -1 sel (ssget "_X" (list '(0 . "HATCH") (cons 410 (getvar 'CTAB))))) (alert "No hatch objects found in current space !") ) (while (setq int (1+ int) ent (ssname sel int) ) (or (member (setq pat (cdr (assoc 2 (entget ent)))) lst) (setq lst (cons pat lst)) ) ) (or (textscr) t) (princ "\nHatch Patterns found : ") (foreach itm lst (princ (strcat "\n" itm)) ) ) (princ) ) 1 Quote
mhupp Posted June 14, 2022 Posted June 14, 2022 You are missing brackets. I suggest getting something like notepad++ that will highlight this for you. I think Autocad passed it off to "visual studio code" now. A bit more advanced software but still free. and has add-ins to help with programming. Here is a look at Blade BricsCAD's lisp editor. sorry forgot a few things with the ssget If your using ssget without a variable it can be done like this. if your only wanting to find a specific type of thing without user input this is the way to go. (setq ss (ssget "_X" '((0 . "HATCH") (2 . "B-B-U0013_L6") (410 . "Model")))) if your using a variable has to have (list and use (cons where the variable is. other sections have to have a ' in front (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 410 (getvar 'ctab))))) A little more help. this will show you the different types of ways to do a rectangle. their are more but these are just a few simple examples. (defun C:TEST (/ ss) (if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 410 (getvar 'ctab))))) ;find all blocks on current tab (prompt (strcat "There are " (itoa (sslength ss)) " Blocks On " (getvar 'ctab) " tab")) (prompt "There are 0 Blocks in the Drawing") ) (alert "createing a rectangle with points that are strored as Varabile's") (setq rip1 (getpoint "\nPick First Point")) (setq rip2 (getpoint "\nPick Second Point")) (command "RECTANG" rip1 rip2) ;places rectangle "boundry for Hatch (alert "createing a rectangle with user picked points during command") (command "_.RECTANG" pause pause) (alert "createing a rectangle at a defined locaiton") (command "_.RECTANG" "0,-5" "5,0") (princ) ) Quote
pttr Posted June 15, 2022 Author Posted June 15, 2022 I´m sorry was tired yesterday. However I still can´t get it to work as intended (defun c:test (/ blockss) (if (setq blockss (ssget "_X" '((0 . "HATCH") (2 . "B-B-U0013_L6") (410 . "Model")))) ;find block B-B-U0013_L6 blocks on current Model (princ "It exist") ) (princ "test") ) If I remove (2 . "B-B-U0013_L6") It works fine but I guess its no use to me if I cant check the specific hatch/layer name. Quote
mhupp Posted June 15, 2022 Posted June 15, 2022 (edited) Use the Dumpit lisp on the hatch your wanting to find. probably isn't named "B-B-U0013_L6" and thus excluded from the selection set. : DUMPIT Select Entity to Dump (-1 . <Entity name: 536ca420>) (0 . "HATCH") (5 . "2077A") (102 . "{ACAD_XDICTIONARY") (360 . <Entity name: 536cb0a0>) (102 . "}") (330 . <Entity name: 27d87360>) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (370 . -1) (100 . "AcDbHatch") (10 0.0 0.0 0.0) (210 0.0 0.0 1.0) (2 . "ANSI31") ... to select/find this hatch in model space would be (if (setq hatchss (ssget "_X" '((0 . "HATCH") (2 . "ANSI31") (410 . "Model")))) (prompt "\nHatch ANSI31 exists in drawing") (prompt "\nHatch ANSI31 doesn't exists in drawing") ) -edit If this hatch is inside a block. I don't think you can find it with a normal ssget. https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-select-all-entities-inside-of-a-block/m-p/10284355/highlight/true#M414750 Edited June 15, 2022 by mhupp Quote
pttr Posted June 15, 2022 Author Posted June 15, 2022 Okay okay I have been reading and reading Problem is 2. is pattern name and not the hatch. I have multiple hatches with same pattern witch means i cant find the right one. In fact the only values separating the hatches i found was true color value and the layer. I thougt I was smart enugh to use true color as a condition but i failed. used this http://www.lee-mac.com/colourconversion.html to convert rgb to true color, but I think it´s wrong... RGB: 188,226,0 True color: 12388864" Then I tried this code: (defun c:test (/ blockss) (if (setq blockss (ssget "_X" '( (0 . "HATCH") (420 . "12388864") (410 . "Model") ))) ;find all blocks on current Model (princ "It exist") ) (princ "test") ) When I run it I get "Bad ssget list value" Any Idea how to move forward? All help is so appreciated! Quote
mhupp Posted June 15, 2022 Posted June 15, 2022 On 6/14/2022 at 12:23 PM, mhupp said: 62 doesn't need quotes. Close, number values don't use quotes. Again if you used the dumpit lisp on the hatch you want to select you would see that (420 . doesn't use quotes. then all you have to do is copy it from the command prompt and add it to your ssget. http://docs.autodesk.com/ACD/2011/ENU/filesDXF/WS1a9193826455f5ff18cb41610ec0a2e719-7a13.htm (defun c:test (/ blockss) (if (setq blockss (ssget "_X" '((0 . "HATCH") (420 . 12388864) (410 . "Model")))) ;find hatch with true color 12388864 (prompt "\nIt exist") (prompt "\nNope") ) (prompt "\nEND") ) Quote
pttr Posted June 15, 2022 Author Posted June 15, 2022 Many thanks it still didn´t work.(Think color is wrong) But I just relized that the only hatch that will ever be placed on the layer is the hatch im looking for! (defun c:test (/ blockss) (if (setq blockss (ssget "_X" '( (0 . "HATCH") (8 . "B-B-U0013") (410 . "Model") ))) ;find specific blocks on current Model (prompt "\nIt exist") (prompt "\nNope") ) (princ "test") ) This was the solution, could not have done it without you mhupp! Thanks! 1 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.