Jump to content

Recommended Posts

Posted

The second code listed below is what I need help with. Why does it not work? I'm trying to analyze it and move things here and there but can't figure it out. I did a test in acad to just pop up an alert using this sample:

 

foreach lay (layoutlist)(command "._layout" "set" lay)(alert "hi"))

 

that worked. It popped up an alert, then when I clicked ok, went to the next tab and did it, and so on. I need the LISP to go to each tab, read the appropriate text value, and store it in the .csv. I'm sure it's something simple, please be gentle :oops:

 

(defun getdata (/)
   (foreach lay (layoutlist)
   (command "._layout" "set" lay)
       ((command "pspace")
       (setq xnum(ssget "_W" (list 49 0)(list 0 37) '((0 . "MTEXT") (-3 ("MMI-SHTNUM")))))
       (setq xname(ssget "_W" (list 49 0)(list 0 37) '((0 . "MTEXT") (-3 ("MMI-SHTNAME")))))
       (setq snum(vla-get-textstring(vlax-ename->vla-object (ssname xnum 0))))
       (setq sname(vla-get-textstring(vlax-ename->vla-object (ssname xname 0))))
   ;(setq layout1 (getvar "ctab"))
       (write-line (strcat snum "," sname) slist1))
   )
   ;(setvar "ctab" clayout)
)

(defun c:slist (/)
   (setq clayout (getvar "ctab"))
   (setq slist1 (open (strcat (getvar "dwgprefix") "Sheetlist.csv") "w"))
   (write-line "SHEET NUMBER,SHEET NAME" slist1)
   (getdata)
   (close slist1)
   (setvar "ctab" clayout)
   (princ)
)

Posted

You have extra bracket

 

[highlight]([/highlight](command "pspace")

 

I don't know though what kind of MTEXT entity has dxf association (-3 ("MMI-*")), maybe I don't know something you do?

 

M.R.

Posted
I don't know though what kind of MTEXT entity has dxf association (-3 ("MMI-*")), maybe I don't know something you do?

 

It is an xData AppID filter ;)

Posted

Xdata indeed :D

 

@marko - that's not an extra bracket. i put that set in there to group the following functions.

Posted
@marko - that's not an extra bracket. i put that set in there to group the following functions.

 

You can't 'group' functions with brackets in LISP.

Posted

:oops:well I didn't mean group as anything more than for my own organizational tool. Even if I remove those extra brackets, the code still doesn't work.

Posted

Consider this [untested] code:

 

(defun c:slist ( / ctab file s1 s2 )
   (if
       (and
           (setq file (findfile (strcat (getvar 'DWGPREFIX) "Sheetlist.csv")))
           (setq file (open file "w"))
       )
       (progn
           (setq ctab (getvar 'CTAB))
           (write-line "SHEET NUMBER,SHEET NAME" file)

           (foreach layout (layoutlist)
               (setvar 'CTAB layout)
               (command "_.zoom" "_E")
               (if
                   (and
                       (setq s1 (ssget "_W" '(49 0) '(0 37) '((0 . "MTEXT") (-3 ("MMI-SHTNUM")))))
                       (setq s2 (ssget "_W" '(49 0) '(0 37) '((0 . "MTEXT") (-3 ("MMI-SHTNAME")))))
                   )
                   (write-line
                       (strcat
                           (cdr (assoc 1 (entget (ssname s1 0)))) ","
                           (cdr (assoc 1 (entget (ssname s2 0))))
                       )
                       file
                   )
                   (princ (strcat "\nMText not found in layout: " layout))
               )
           )
           (close file)
           (setvar 'CTAB ctab)
       )
       (princ "\nFile not found or could not be opened.")
   )
   (princ)
)

Posted

On initial testing, this works.

 

Mr. Mac...I'm sure this is the first time you've heard this but you are the man. :D For my knowledge, did you notice why my code was failing? From my semi-novice eyes it seems pretty similar but I'm thinking it was failing because of the way I had the "foreach" setup....

Posted

Thanks :)

 

It could be the Zoom Extents in my code before retrieving the SelectionSet, since, for a window/crossing selection, the objects must be visible on screen to be selected. Other than that I just added some error trapping and used the CTAB Sys Var to switch layouts instead of a command call to the Layout command.

 

You might want to modify my code by changing the selection set filter list to:

 

(list '[font=monospace][/font](0 . "MTEXT") '(-3 ("MMI-SHTNUM")) (cons 410 layout))

 

so that only those MText in layout space are selected.

 

Happy to help,

 

Lee

Posted

gotcha...I didn't even think of using the CTAB versus layout. I will append with your recommendation and have added some minor things as well.

 

I might be back with some questions. :thumbsup:

Posted

Question, if we're "closing" the csv file for write, why when I open it afterwards does it say it's read-only?

Posted

Hmm, so now the read-only is sporadic. Sometimes it's prompts that, sometimes it doesn't.

 

Also, and maybe I'm digging too deep a hole here...this works great for my 1 ACAD file...however the reality is we would have anywhere from 3 to maybe 10 or more CAD files that this needs to account for. We have our sheets on layout tabs and I wanted to this be able to be used for the CAD guys to know what sheet names have been created already if they're creating new ones as well as when our field guys call up and reference a plan, we can easily find out which CAD file it's on and go to it (I modified the code to write that data as well).

 

My first thought was to have this open all of our CAD files and run this routine to populate the Sheet List. But that would take so long with as big as our models are and as many sheets as we have. Is there an easier way?

 

And before you say it, we can't use Sheet Set Manager b/c to my knowledge, are workflow is backwards for it. SSM is setup if you have 1 sheet per CAD file. Due to limitations of a third-party program, we cannot have that luxury so all sheets for that model have to be on that CAD file.

 

Thanks for any help!

Posted
Question, if we're "closing" the csv file for write, why when I open it afterwards does it say it's read-only?

 

If the program crashed before the file descriptor was closed, and the variable pointing to the descriptor was localised and hence no longer accessible, the file will become read-only, since the file descriptor still exists in memory - you would need to restart ACAD to free-up the descriptor.

 

To avoid this situation, I include a localised *error* handler with some expressions to check whether the variable pointing to the file descriptor is valid, and, if so, close the file if open.

Posted

Also, and maybe I'm digging too deep a hole here...this works great for my 1 ACAD file...however the reality is we would have anywhere from 3 to maybe 10 or more CAD files that this needs to account for. We have our sheets on layout tabs and I wanted to this be able to be used for the CAD guys to know what sheet names have been created already if they're creating new ones as well as when our field guys call up and reference a plan, we can easily find out which CAD file it's on and go to it (I modified the code to write that data as well).

 

My first thought was to have this open all of our CAD files and run this routine to populate the Sheet List. But that would take so long with as big as our models are and as many sheets as we have. Is there an easier way?

 

And before you say it, we can't use Sheet Set Manager b/c to my knowledge, are workflow is backwards for it. SSM is setup if you have 1 sheet per CAD file. Due to limitations of a third-party program, we cannot have that luxury so all sheets for that model have to be on that CAD file.

 

Thanks for any help!

 

Would anyone have any insight on this while I have downtime to get this perfected?

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