Ahankhah Posted October 23, 2011 Posted October 23, 2011 Hi All, How is it possible to add file(s) to "CAD Standards" to check the current drawing for any violation via LISP? P.S. I have found a nice code to delete the previously added files from drawing, in the following address: Can you delete (DWS) files with a LISP routine? So many thanks to Blown Big Block and my dear friend, Lee Mac. ... But my question is still unanswered. Quote
Ahankhah Posted October 23, 2011 Author Posted October 23, 2011 (edited) I got some useful AutoLISP codes here. Many thanks to Stig Madsen and Afralisp. But still seeking Vanilla... Edited October 23, 2011 by Ahankhah Quote
Lee Mac Posted October 23, 2011 Posted October 23, 2011 Try something like this Mehrdad, ([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] file ) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] file ([color=BLUE]getfiled[/color] [color=MAROON]"Select DWS File"[/color] [color=MAROON]""[/color] [color=MAROON]"dws"[/color] 16)) (AddDWSAssociation file) ) ) [color=GREEN];; Add DWS Association - Lee Mac[/color] [color=GREEN];; dws = filename of DWS file.[/color] [color=GREEN];; Returns XRecord entity name if successful[/color] ([color=BLUE]defun[/color] AddDWSAssociation ( dws [color=BLUE]/[/color] dict elst i item lst ) ([color=BLUE]setq[/color] dict ([color=BLUE]if[/color] ([color=BLUE]setq[/color] dict ([color=BLUE]dictsearch[/color] ([color=BLUE]namedobjdict[/color]) [color=MAROON]"AcStStandard"[/color])) ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] -1 dict)) ([color=BLUE]dictadd[/color] ([color=BLUE]namedobjdict[/color]) [color=MAROON]"AcStStandard"[/color] ([color=BLUE]entmakex[/color] '( (0 . [color=MAROON]"DICTIONARY"[/color]) (100 . [color=MAROON]"AcDbDictionary"[/color]) (280 . 0) (281 . 1) ) ) ) ) ) ([color=BLUE]setq[/color] elst ([color=BLUE]entget[/color] dict)) ([color=BLUE]while[/color] ([color=BLUE]setq[/color] item ([color=BLUE]assoc[/color] 350 elst)) ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] ([color=BLUE]list[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 1 ([color=BLUE]entget[/color] ([color=BLUE]cdr[/color] item)))) ([color=BLUE]cdr[/color] item) ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 3 elst)) ) lst ) ) ([color=BLUE]setq[/color] elst ([color=BLUE]cdr[/color] ([color=BLUE]member[/color] item elst))) ) ([color=BLUE]if[/color] ([color=BLUE]assoc[/color] dws lst) ([color=BLUE]cadr[/color] ([color=BLUE]assoc[/color] dws lst)) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] lst ([color=BLUE]mapcar[/color] '[color=BLUE]caddr[/color] lst) i -1 ) ([color=BLUE]while[/color] ([color=BLUE]member[/color] ([color=BLUE]itoa[/color] ([color=BLUE]setq[/color] i ([color=BLUE]1+[/color] i))) lst)) ([color=BLUE]dictadd[/color] dict ([color=BLUE]itoa[/color] i) ([color=BLUE]entmakex[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"XRECORD"[/color]) '(100 . [color=MAROON]"AcDbXrecord"[/color]) '(280 . 1) ([color=BLUE]cons[/color] 1 dws) ) ) ) ) ) ) Quote
Ahankhah Posted October 24, 2011 Author Posted October 24, 2011 Excellent Thank you very much Lee. Quote
Lee Mac Posted October 24, 2011 Posted October 24, 2011 Excellent Thank you very much Lee. You're welcome Ahankhah - if you have any questions about the code, just ask. Quote
bennyboy86 Posted October 26, 2011 Posted October 26, 2011 hello Lee Mac, could you help me i have had a look at the code but i dont understand what i have to do it to make it work for me. I have done some basic lisp before and know how to load them etc. but in reading the code got nothing. hopefully you can explain like a dummy guide for me. thanks. Quote
Ahankhah Posted October 27, 2011 Author Posted October 27, 2011 (edited) The Lee's code adds a DWS file to "Standards" command without needing to sequentially (1) open the dialog, (2) press + botton, (3) then select the DWS file to add it to the left listbox of dialog. Edited October 27, 2011 by Ahankhah Quote
Lee Mac Posted October 27, 2011 Posted October 27, 2011 could you help me i have had a look at the code but i dont understand what i have to do it to make it work for me. I have done some basic lisp before and know how to load them etc. but in reading the code got nothing. hopefully you can explain like a dummy guide for me. The function 'AddDWSAssociation' is a function requiring one argument: the filename of the DWS file to be associated with the active DWG file. You would call the function AddDWSAssociation as you would any other LISP function requiring arguments, for example, the '+' function requires one or more numerical arguments: (+ 1 2 3) ==> 6 (AddDWSAssociation "C:\\YourFolder\\YourDWSFile.dws") ==> <Entity Name of XRecord> In my code above, I have included another function: 'c:test' which may be called at the command-line (since it includes the 'c:' prefix). This function (c:test) calls the AddDWSAssociation function with the filename of a DWS file if the user has selection such a file from the getfiled dialog. Quote
amir Posted February 24, 2016 Posted February 24, 2016 (edited) (AddDWSAssociation "C:\\YourFolder\\YourDWSFile.dws") ==> <Entity Name of XRecord> In my code above, I have included another function: 'c:test' which may be called at the command-line (since it includes the 'c:' prefix). This function (c:test) calls the AddDWSAssociation function with the filename of a DWS file if the user has selection such a file from the getfiled dialog. What am I doing wrong? I get the message: Invalid search pattern *.C:\SCRIPTS\986116\TataStandard2012.dws . De code: (defun c:test ( / file ) (if (setq file (getfiled "Select DWS File" "" "C:\\SCRIPTS\\986116\\TataStandard2012.dws" 16)) (AddDWSAssociation file) ) ) ;; Add DWS Association - Lee Mac ;; dws = filename of DWS file. ;; Returns XRecord entity name if successful (defun AddDWSAssociation ( dws / dict elst i item lst ) (setq dict (if (setq dict (dictsearch (namedobjdict) "AcStStandard")) (cdr (assoc -1 dict)) (dictadd (namedobjdict) "AcStStandard" (entmakex '( (0 . "DICTIONARY") (100 . "AcDbDictionary") (280 . 0) (281 . 1) ) ) ) ) ) (setq elst (entget dict)) (while (setq item (assoc 350 elst)) (setq lst (cons (list (cdr (assoc 1 (entget (cdr item)))) (cdr item) (cdr (assoc 3 elst)) ) lst ) ) (setq elst (cdr (member item elst))) ) (if (assoc dws lst) (cadr (assoc dws lst)) (progn (setq lst (mapcar 'caddr lst) i -1 ) (while (member (itoa (setq i (1+ i))) lst)) (dictadd dict (itoa i) (entmakex (list '(0 . "XRECORD") '(100 . "AcDbXrecord") '(280 . 1) (cons 1 dws) ) ) ) ) ) ) Edited February 24, 2016 by SLW210 Added Code Tags Quote
Lee Mac Posted February 24, 2016 Posted February 24, 2016 Change: (defun c:test ( / file ) (if (setq file (getfiled "Select DWS File" "" "C:\\SCRIPTS\\986116\\TataStandard2012.dws" 16)) (AddDWSAssociation file) ) ) to: (defun c:test ( / dws ) (if (findfile (setq dws "C:\\SCRIPTS\\986116\\TataStandard2012.dws")) (AddDWSAssociation dws) (princ (strcat "\n" dws " not found.")) ) (princ) ) I would also suggest that you read the documentation for the getfiled function. 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.