TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Amsterdammed on October 11, 2010, 08:02:51 AM

Title: document manager
Post by: Amsterdammed on October 11, 2010, 08:02:51 AM
Hello there!

I ask just to prevent inventing the wheel again.
I always work with two screens and lovepaperless working, since I travel a lot with my work. SO i always have acad running on one screen and the information i need to design on the other screen, mostly pdf. So everytime i start working i need to open all the documents related to that deg I'm working on. I thought about storing the paths of the document in the deg and open them with a lisp.

I assume others have the same demand for a thing like that and therefore the code might be written already.

Thanks in advance

Bernd
Title: Re: document manager
Post by: Lee Mac on October 11, 2010, 08:08:16 AM
A nice idea - if one did not exist, I'd be willing to spend some time putting one together perhaps  :-)
Title: Re: document manager
Post by: HasanCAD on October 11, 2010, 08:24:09 AM
A nice idea, I am facing the same problem.
Title: Re: document manager
Post by: huiz on October 11, 2010, 09:04:33 AM
You can add hyperlinks to objects. Just put some objects (ie texts describing the needed documents) somewhere outside the drawing, add a hyperlink to those objects and CTRL+click - voila!
Title: Re: document manager
Post by: JohnK on October 11, 2010, 09:13:54 AM
You can add hyperlinks to objects. Just put some objects (ie texts describing the needed documents) somewhere outside the drawing, add a hyperlink to those objects and CTRL+click - voila!

second that.
Title: Re: document manager
Post by: Amsterdammed on October 11, 2010, 10:00:48 AM
I though more about to open the files the first time with getfiled and store the location in non graphic data and then have a command to reopen them the next time, so no big thing at all.
Title: Re: document manager
Post by: JohnK on October 11, 2010, 10:16:02 AM
Okay, quick questions:
Would this progy automatically open the files (all, some, or last)? ...what happens if the file doesnt exist? What happens if the files are not needed any longer (5 yrs down the road)--a persistent reactor (if you decide to go that route) would be a real pain.
Title: Re: document manager
Post by: Amsterdammed on October 11, 2010, 10:25:25 AM
no reactor. Dictionary and you open it on command., so no reactor needed You can show them in a list first and you select what you want to open, and of course you look if the are still there
Title: Re: document manager
Post by: JohnK on October 11, 2010, 10:59:27 AM
like a simple list box? ...cool.
Title: Re: document manager
Post by: deegeecees on October 11, 2010, 11:09:28 AM
Like a command to store open files, then write those paths to xdata. Then a command to pull that info into a listbox for retrieval. Sounds like a good idea.
Title: Re: document manager
Post by: Amsterdammed on October 11, 2010, 11:14:13 AM
a command to open the files in the first place wit getfiled, so you already have the path. then sore it  and get it back with a listbox to select
Title: Re: document manager
Post by: Lee Mac on October 11, 2010, 01:18:25 PM
Quickly scribbled together:

Code: [Select]
(defun c:docset ( / file lst )
  (vl-load-com)
  ;; © Lee Mac 2010

  (if
    (while (setq file (getfiled "Select File to Add to Drawing" (cond ( file (vl-filename-directory file) ) ( "" )) "" 16))
      (setq lst (cons file lst))
    )
    (vlax-ldata-put "DocManagerDocs" "docs" (acad_strlsort lst))
  )

  (princ)
)

(defun c:docget ( / _OpenFiles data )
  (vl-load-com)
  ;; © Lee Mac 2010

  (defun _OpenFiles ( files / Shell )
    (setq Shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))

    (mapcar
      (function
        (lambda ( file )
          (if
            (vl-catch-all-error-p
              (vl-catch-all-apply
                (function vlax-invoke) (list Shell 'Open file)
              )
            )
            (princ (strcat "** Error Opening: " file " **"))
          )
        )
      )
      files
    )

    (vlax-release-object Shell)
  )

  (if (setq data (vlax-ldata-get "DocManagerDocs" "docs"))
    (_OpenFiles
      (vlax-ldata-put "DocManagerDocs" "docs"
        (vl-remove-if-not 'findfile data)
      )
    )   
  )

  (princ)
)

DocSet, stores filename data in drawing dictionary, continuous file selection prompts until user hits cancel.

DocGet, opens stored files.

I'm sure it could be improved upon,

Lee
Title: Re: document manager
Post by: stevesfr on October 11, 2010, 01:52:39 PM
Lee, it boms here thus:

Command: appload
docset.lsp successfully loaded.


Command: ; error: bad argument type: numberp: nil

Steve
Title: Re: document manager
Post by: Lee Mac on October 11, 2010, 02:10:18 PM
I can't seem to reproduce that Steve, furthermore, the code doesn't use any functions which are supplied predominantly with numbers, so I'm a little perplexed at that  :-(
Title: Re: document manager
Post by: Amsterdammed on October 11, 2010, 02:25:42 PM
It works with no problem here....
thanks!!
Title: Re: document manager
Post by: Lee Mac on October 11, 2010, 02:33:15 PM
You're welcome Bernd, it was just a sketch code of the ideas expressed in the thread, I'm sure it could be greatly improved upon  :-)
Title: Re: document manager
Post by: stevesfr on October 11, 2010, 03:26:50 PM
Lee, my fault somewhere...
copied it again and loaded it into vanilla drawing and presto !!!!!!!!!
sorry, should have investigated further before pulling the panic chain...
Steve
Title: Re: document manager
Post by: Lee Mac on October 11, 2010, 03:34:57 PM
No worries Steve  8-)
Title: Re: document manager
Post by: Amsterdammed on October 12, 2010, 05:08:28 AM
Now the next thing would be (but here you need a reactor for and i don't like them) to close the docs once you close the dwg......
Title: Re: document manager
Post by: jbuzbee on October 12, 2010, 11:22:55 AM
Quote
Now the next thing would be (but here you need a reactor for and i don't like them) to close the docs once you close the dwg......

OpenDCL - Modeless Dialog - OnDocActivated (fires when closing or switching documents)
                                        EnteringNoDocState (just what it says)

Dialog could be used as a GUI or made invisible to just utilize the Events.

just a thought.

jb
Title: Re: document manager
Post by: Amsterdammed on October 12, 2010, 12:27:36 PM
not just a thought, burt a good one :-)
Title: Re: document manager
Post by: jbuzbee on October 13, 2010, 01:35:28 PM
OK, so I got sucked into a challenge and now I can't back out!

I haven't done dictionary stuff in a while: I'm attempting to store a list of drawing names but can't seem to figure it out.  (cons 3 dwgList) returns (3 "dwg1" "dwg2") and errors while entmaking. 

Lee, I saw you used ldata: I stay as far away from that as possible.  I don't know if they fixed that but I had a slew of drawings corrupted back in 2004 thanks to Ldata (so did a lot of other people).

So whats the best way to store associated drawings?

Oh, a little teaser:

(http://img838.imageshack.us/img838/743/teasers.gif)

Title: Re: document manager
Post by: T.Willey on October 13, 2010, 01:41:26 PM
You could store them as Xrecords within a custom dictionary within the drawings.
Title: Re: document manager
Post by: Lee Mac on October 13, 2010, 01:43:28 PM
Lee, I saw you used ldata: I stay as far away from that as possible.  I don't know if they fixed that but I had a slew of drawings corrupted back in 2004 thanks to Ldata (so did a lot of other people).

Oh right - that's news to me, thanks James. I see quite a few other guys here use LData, so I thought it might be the way to go  :-)
Title: Re: document manager
Post by: jbuzbee on October 13, 2010, 01:51:24 PM
Tim, that's what I'm trying to do.  I get caught up with:

(cons 3 dwgList) returns (3 "dwg1" "dwg2") and errors while entmaking. 

Lee, maybe they fixed it - but once burned . . ..

Thanks for any help!
Title: Re: document manager
Post by: dgorsman on October 13, 2010, 01:54:44 PM
I find data dictionaries and XRecords easier to manage through (vla-...), if that helps.  The "collection" nature of the dictionary makes it a little easier to follow than with individual DXF dotted pairs.
Title: Re: document manager
Post by: T.Willey on October 13, 2010, 01:57:39 PM
Tim, that's what I'm trying to do.  I get caught up with:

(cons 3 dwgList) returns (3 "dwg1" "dwg2") and errors while entmaking. 

Lee, maybe they fixed it - but once burned . . ..

Thanks for any help!

Maybe this by MP will help.

[ http://www.theswamp.org/index.php?topic=5003.0 ]
Title: Re: document manager
Post by: Lee Mac on October 13, 2010, 02:18:17 PM
Great thread - thanks Tim for the link (and many thanks to MP for the explanations).
Title: Re: document manager
Post by: jbuzbee on October 13, 2010, 03:12:54 PM
Ok, I guess I'll punt:

(cons 3 dwglist)

returns

(3 . "Drawing1.dwg;Drawing2.dwg;Drawing3.dwg")<-- note this is one string, the files seperated by a smi-colon.  I'll parse the string that way.

See what I'm getting at?

if dwglist were a list of strings: (setq  dwgList(list "Drawing1.dwg" "Drawing2.dwg" "Drawing3.dwg"))

I am unable to create the proper assosiation with (cons 3 dwgList):

That returns (3 "Drawing1.dwg" "Drawing2.dwg" "Drawing3.dwg")

??
Title: Re: document manager
Post by: alanjt on October 13, 2010, 03:25:43 PM
What about a list?
eg.
Code: [Select]
(cons 3 (list dwglist))
Title: Re: document manager
Post by: Lee Mac on October 13, 2010, 03:26:11 PM
I'm pretty inexperienced at using XRecords, but here are the options I would consider, assuming the filenames are in a list:

Code: [Select]
(cons <integer> (vl-prin1-to-string filenamelist))

Then, to read it back:

Code: [Select]
(read (cdr (assoc <integer> <XRecordData>)))
Or, using data delimiters (as you mention, semi-colons perhaps)

Code: [Select]
(cons <integer> "filename;filename;filename")
But, in my inexperience with XRecords, I myself have a few questions - what <integer> should be used? 0-9 or any other integer accepting a string argument? (referring to DXF Types here (http://autodesk.com/techpubs/autocad/acad2000/dxf/group_code_value_types_dxf_01.htm)).

Also, could using multiple entries be an option? (is this allowed?)

Lee

Title: Re: document manager
Post by: jbuzbee on October 13, 2010, 03:37:40 PM
Thanks Alan / Lee,

I solved it with a pass through a string parser: lots more to do, can't get hung up on one thing!  :lol:
Title: Re: document manager
Post by: alanjt on October 13, 2010, 03:38:51 PM
Thanks Alan,

I solved with a pass through a string parser: lots more to do, can't get hung up on one thing!  :lol:
Right on; just an attempt to avoid having to parse to and from a string.
Title: Re: document manager
Post by: Lee Mac on October 13, 2010, 03:51:20 PM
What about a list?
eg.
Code: [Select]
(cons 3 (list dwglist))

Can DXF 3 accept a list though? Can any DXF integer accept a list other than that of a 2/3D point?

I thought 0-9 could only take strings.
Title: Re: document manager
Post by: alanjt on October 13, 2010, 03:53:50 PM
What about a list?
eg.
Code: [Select]
(cons 3 (list dwglist))

Can DXF 3 accept a list though? Can any DXF integer accept a list other than that of a 2/3D point?

I thought 0-9 could only take strings.
Crap, good point.
Title: Re: document manager
Post by: dgorsman on October 13, 2010, 03:54:35 PM
Theres a couple of ways I would try it.  The first would be to use multiple XRecords with keys of "Doc1", "Doc2", through "Doc(n)" to allow later iteration, each with a single ( 3 . "DocPathHere") element.  The other would be to have a single "MyLinkedDocs" XRecord with multiple ( 3 . "DocPathHere1" ) ( 3 . "DocPathHere2" ) ( 3 . "DocPathHereN" ) elements, each pointing to a single file.  You could then pull all "3" prefixed items from the assoc list for later processing.  If needed they could be surrounded by a DXF 102 group to localize them.

The choice of DXF code depends on whats being stored; 3 is good for a path name, but if multiple text items were being stored I would consider using unique codes from the 300-309 sequence.
Title: Re: document manager
Post by: Lee Mac on October 13, 2010, 03:59:09 PM
Also, could using multiple entries be an option? (is this allowed?)

The other would be to have a single "MyLinkedDocs" XRecord with multiple ( 3 . "DocPathHere1" ) ( 3 . "DocPathHere2" ) ( 3 . "DocPathHereN" ) elements, each pointing to a single file.  You could then pull all "3" prefixed items from the assoc list for later processing.  If needed they could be surrounded by a DXF 102 group to localize them.

Question answered, thanks mate :-)
Title: Re: document manager
Post by: dgorsman on October 13, 2010, 04:07:45 PM
No problem.  Because the data inside the XRecords doesn't have a keyed index I tend to get lots of XRecords each with a little bit of data.  Unique DXF codes can make it easier but since there are only so many to choose from its easy to "run out".  That means the software must interpret the order of data and anything that modifies the list must take the order into account.
Title: Re: document manager
Post by: T.Willey on October 13, 2010, 05:43:25 PM
James,

  See if you can use these in conjuncture with what MP did in the other post.  It seems to work for me.

Code: [Select]
(defun UpdateDrawingList ( dwgList / Dict )
   
    (setq Dict (GetOrAddDict (namedobjdict) "AssociatedDrawings"))
    (foreach dwg dwgList
        (AddOrReplaceXrec Dict (vl-filename-base dwg) (list (cons 1 dwg)))
    )
)
;---------------------------------------------------------
(defun GetDrawingList ( / Data DwgList )
   
    (setq Data (entget (GetOrAddDict (namedobjdict) "AssociatedDrawings")))
    (while (setq Data (member (assoc 3 Data) Data))
        (setq DwgList (cons (cdr (assoc 1 (entget (cdadr Data)))) DwgList))
        (setq Data (cdr Data))
    )
    DwgList
)
;---------------------------------------------------------
(defun RemoveDrawing ( path / Dict Data Name )
   
    (setq Dict (GetOrAddDict (namedobjdict) "AssociatedDrawings"))
    (if
        (and
            (setq Data (dictsearch Dict (setq Name (vl-filename-base path))))
            (= (strcase (cdr (assoc 1 Data))) (strcase path))
        )
        (dictremove Dict Name)
    )
)
Title: Re: document manager
Post by: Jeff H on October 14, 2010, 03:25:03 PM
I have a App that is .NET that is similar, I could strip it down because you would select the project then it grouped it by drawing type(1-lines, details, ets) and listed the file name and drawing name in title block. And would let you choose how many recent projects to show. They have a extra computer on the network that does not get used much so I added a app that runs that with a filesystemwatcher to keep up if drawings are deleted or moved.

Come to think of it it would be easy to create a winform where you select the project  and it would all drawings and pdf's for you.

If you need it let me know.

Sorry it gets lonley over at the NET forum and watching all of you constantly posting cool applications.
Title: Re: document manager
Post by: jbuzbee on October 14, 2010, 04:40:28 PM
Quote
Sorry it gets lonley over at the NET forum and watching all of you constantly posting cool applications.

Darkside isn't all that they promised, eh?  Since you asked nice you come back . . .  :wink: