Jump to content

Recommended Posts

Posted (edited)

I got some useful AutoLISP codes here.

Many thanks to Stig Madsen and Afralisp.

 

But still seeking Vanilla...

Edited by Ahankhah
Posted

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

Posted

Excellent :o

Thank you very much Lee. :D

Posted
Excellent :o

Thank you very much Lee. :D

 

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

Posted

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.

Posted (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 by Ahankhah
Posted
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.

  • 4 years later...
Posted (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 by SLW210
Added Code Tags
Posted

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.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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