sekarr24 Posted July 7, 2011 Share Posted July 7, 2011 Hi., I need a lisp routine to count the number of layouts (layouts name will be not be specific & is random ) in a drawing from starting to end, and update the sheet no field in the title block ex: '1 of 5', '2 of 5', etc... Can any one guide how to do it?? regards r.sekar Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 7, 2011 Share Posted July 7, 2011 This would give you the number of layouts that you have in a drawing . (length (layoutlist)) But what do you mean by update the sheet no field in the title block ? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 7, 2011 Share Posted July 7, 2011 In Pseudo Code it might be something along the lines of: Initialise counter variable to 1 and another variable to store number of layouts (as a string) (setq sheet 1) (setq total (itoa (length (layoutlist)))) Iterate through list of layouts. (foreach layout (layoutlist) ... ) For each layout name, acquire a SelectionSet of attributed blocks of a specific name inserted in that layout (ssget "_X" (list (cons 0 "INSERT") (cons 66 1) (cons 2 "YourBlockName") (cons 410 layout))) Iterate through the attributes of each block in the SelectionSet (entnext) Update the attribute with tag pertaining to the sheet number using a concatenation of the counter variable and variable containing total number of layouts (strcat (itoa sheet) " of " total) Increment the counter (setq sheet (1+ sheet)) Quote Link to comment Share on other sites More sharing options...
woodman78 Posted July 8, 2011 Share Posted July 8, 2011 r.sekar, There is a much easier way to do it with fields. The only thing is that you would need to number the layouts as 1,2,3,4,5.....etc. And use another field for the total number pages. I have it setup this way and it works very well. A simple regenall updates the fields. I attach a layout with the fields. Note also a field used for the scale. If you change the viewport scale and regenall the scale updates. The sheet size is updated based on the Page Setup used to plot. new block.dwg Quote Link to comment Share on other sites More sharing options...
irneb Posted July 9, 2011 Share Posted July 9, 2011 It's not working for me: I note that your total is coming from the USERS5 system variable. You probably have some lisp setting it for you. This is why I don't like doing it this way - if the field is used on a ACad which doesn't have that Lisp loaded, you get what's displayed in my screen capture. Quote Link to comment Share on other sites More sharing options...
johmmeke Posted July 10, 2011 Share Posted July 10, 2011 Not working here also. Regen has no effect. I know by experience that if u use a field in a attribute, you can't get the code back that was inserted. Can you please give the code you inserted, and in what kind of field, sorry stil very new to this. Mvg John not native english Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 10, 2011 Share Posted July 10, 2011 I haven't looked at the drawing, but I would guess that woodman has used a field referencing a LISP Variable (or User System Variable which is updated by a LISP code) to display the total number of layouts. Since a LISP variable will only hold its value during the current drawing session (while the document namespace exists) it would need to be setq'd every time the drawing is opened for the field to display the correct value. I can't immediately see a way to display the total number of layouts using a field without referencing a LISP Variable or User System Variable, so would recommend the OP follows the directions I describe in post #3. Quote Link to comment Share on other sites More sharing options...
Cad64 Posted July 10, 2011 Share Posted July 10, 2011 I need a lisp routine to count the number of layouts (layouts name will be not be specific & is random ) in a drawing from starting to end, and update the sheet no field in the title block ex: '1 of 5', '2 of 5', etc... I would recommend you learn about "Sheet Sets": http://heidihewett.blogs.com/my_weblog/files/Sheets_Happen.pdf Quote Link to comment Share on other sites More sharing options...
irneb Posted July 11, 2011 Share Posted July 11, 2011 I know by experience that if u use a field in a attribute, you can't get the code back that was inserted.I'm unsure what you're referring to. Firstly woodman's drawing has the fields inside a normal MText inside a block or simply as MText on the layout page (not attributes). Secondly I've never been unable to get at the field-code because it was in an attribute, are you perhaps referring to formula fields? Those have a tendency to become "uneditable" if they are the only thing in text/attrib/table-cell. Woodman's drawing (as I've stated before) loads the "Sheet # of ##" by having 2 fields: (1) a field pointing to the CTab system variable to get the current tab's name. Field code is "%%" (2) a field pointing to a Diesel expression simply retrieving the USERS5 system variable. Field code is "%%". If you're referring to the Date, Issue Date, Scale and Sheet Size, they are respectively: "%%"; "%%"; "%%)*1000/%%).CustomScale \f "%lu2%qf2816">%) \f "%lu2%pr0">%" and "%%". I've got a problem with the last one which gets its value from a lisp variable (which on my PC is nil), same as the USERS5 which is "" (blank text). It might have worked if woodman also attached the LSP which sets/creates these 2. Quote Link to comment Share on other sites More sharing options...
dbroada Posted July 11, 2011 Share Posted July 11, 2011 could it be that Woodman's is a function of Civil? I know electrical has some automatic page numbering and other reference information built in. Quote Link to comment Share on other sites More sharing options...
irneb Posted July 11, 2011 Share Posted July 11, 2011 Possibly ... the ccc_sheet lisp variable might refer to something in Civil perhaps? Which I'm not sure why it's needed, you could have a TB as a DynBlock and then calculate the sheet size into a Lookup parameter - direct link to field should work fine. BTW, if I would do this, I'd prefer making a custom Drawing Property instead of using that UserS5 system variable. Both would get saved to the DWG file, but a custom property can be given a much more descriptive name: Making it less possible for someone else to overwrite it. But of course, that's just me Anyhow, if your list of drawings isn't into several hundreds I'd also advise using SSM - there's a lot more customizability in that than using these DWG-wide variables, not to mention it's much easier adjusting stuff over several DWG files. I've just found that if the SSM contains several hundred drawings it takes ages to open any one of those - so either set the SSMAutoOpen/SSLocate or split your sheet-sets into more manageable groups. Quote Link to comment Share on other sites More sharing options...
sekarr24 Posted July 13, 2011 Author Share Posted July 13, 2011 Hi lee., I tried to code the program as per your comments, but it is not working fine. the code as follows (defun C:cdd () (setq sheet 1) (setq total (itoa (length (layoutlist)))) (foreach layout (layoutlist) (ssget "x" (list (cons 0 "INSERT") (cons 66 1) (cons 2 "title_block") (cons 410 layout))) (setq sheet (1+ sheet)) ) wht is wrong in the above code?? Could you post it as a full-code so that it will be helpful. one more thing how to update attribute with tag.how to do it??? thanks & regards r.sekar Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 13, 2011 Share Posted July 13, 2011 wht is wrong in the above code?? You are collecting the selection set, but not doing anything with it, you will need to iterate through this set and update each block. Look into the functions ssname, entnext, entmod, and entupd. Also, read this with regards to code formatting. Quote Link to comment Share on other sites More sharing options...
irneb Posted July 14, 2011 Share Posted July 14, 2011 And as another recommendation: You're making a new selection set for each layout tab. That could cvause problems as ACad only allows a maximum number of "active" selection sets. These aren't cleared immediately once you stop using them. For that you'll need to set any variable pointing to it to nil and then FORCE a garbage collection through (gc). However, I'd actually omit the 410 filter and select all the blocks in one go. Then as you step through the selection set check the entget data of the current block to match its 410 code to the layout name. That way you only make one single selection set, not 1 through N for each tab. Quote Link to comment Share on other sites More sharing options...
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.