Jump to content
Ahankhah

How to add DWS files with a LISP routine?

Recommended Posts

Ahankhah

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.

Share this post


Link to post
Share on other sites
Ahankhah

I got some useful AutoLISP codes here.

Many thanks to Stig Madsen and Afralisp.

 

But still seeking Vanilla...

Edited by Ahankhah

Share this post


Link to post
Share on other sites
Lee Mac

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)
                   )
               )
           )
       )
   )
)

Share this post


Link to post
Share on other sites
Ahankhah

Excellent :o

Thank you very much Lee. :D

Share this post


Link to post
Share on other sites
Lee Mac
Excellent :o

Thank you very much Lee. :D

 

You're welcome Ahankhah - if you have any questions about the code, just ask. :)

Share this post


Link to post
Share on other sites
bennyboy86

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.

Share this post


Link to post
Share on other sites
Ahankhah

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 by Ahankhah

Share this post


Link to post
Share on other sites
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.

 

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.

Share this post


Link to post
Share on other sites
amir

 

(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 by SLW210
Added Code Tags

Share this post


Link to post
Share on other sites
Lee Mac

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.

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...