Jump to content

editing attributes & viewports over multiple drawings.


Leebles

Recommended Posts

Good morning/afternoon/evening.

I have been a member here for a few years now but have been out of the profession for sometime (also forgot username) so i have set myself up as a new member.

I have recently started using AutoCAD again over the past couple of months and was looking for someone with a bit more knowledge for some input on a project i have just picked up. I need to change 2000 (give or take a few) drawings to a new sheet set. Attributes are pretty much the same (a couple are being removed from the new sheet set all together). Is there a lisp that will allow me to copy attributes out of one sheet set into the new?.

The company have also put some standards and are now working in model/paper space. Original drawings (including drawing sheet) were drawn in model space.

I have the sheet sets now in place and am ready to go but is there a way I can automate this process?

There are two viewports in the main paper model. One at a scale 1:1 and one at a scale 5:1. I am working at a plastics company so profile are generally small.

Would really really appreciate if someone can help me out on this one. Am looking forward to your responses (fingers crossed)

Cheers

Lee

 

(p.s if i havent explained myself clear enough let me know - my biggest problem not explaining things properly)

Link to comment
Share on other sites

There are a lot of ways to automate repetitive process, and there are a number of people who frequent this forum who are well-versed in exactly that. Whatever you're looking for, I'm sure you'll find it here.

 

I haven't used Sheet Sets myself, but there is a help file regarding them. Perhaps your answer lies there?

 

If not, perhaps you could explain the process by which you would take an old .dwg and update it to your new standards. Most commands in AutoCAD can be automated, and if it's as simple as running through a complex series of simple commands once in order to determine a pattern, then consolidating and running the pattern, that would be a slightly time consuming but ultimately worth it piece of cake. Alls we would need is a list of commands and a reasoning for why they're being invoked, what sort of objects are being modified, et cetera.

Link to comment
Share on other sites

Thanks for the reply Freerefill.

 

Ok first task I have to do is to extract attributes from one drawing sheet and transfer it to the new one. These being, drawing originator, date, revision etc etc. I think about 10 all in all.

Second task is to create the profile in model space. These are already created in the old drawings BUT the 1:1 is not dimensioned. Only the scaled version. (each drawing has a 1:1 and a 5:1 or 10:1 depending on the size of the profile).

I have set up the new paper space layouts with viewports and wondered if i could take the scaled profile (with the dimensions) and transfer to the new sheet at 1:1.

 

The client requires a 1:1 model (dimensioned). Paper space viewports will take care of the scaling. I will upload an old sheet and the new proposal and it might make it a bit clearer.

If someone can give me a clue on how to upload dwgs??

 

cheers

Link to comment
Share on other sites

Shew.. that's tricky..

 

Transferring data from one file to the next might require an intermediate file. There are ways to do this, the first one that pops into my mind is creating a LISP that extracts the data and writes to a file, then a separate LISP or Script that reads from that file and inputs the data. I know there are LISPs to read block attribute data (a veritable compendium), it can then be exported to said file, and there's a recent topic in this forum which discussed creating a Script to then put that data back where it belongs. The script file was created using a .bat file, but the same thing could be done directly in the LISP that gathered the data.

 

The second problem is tricky. It seems like it would involve copying the 1:1 profile (I'm assuming this is in Modelspace?) from the old drawing and pasting it in the new drawing. I'm positive that this could be done, but dimensioning might be tricky. If all the profiles are set up a specific way, then it might be possible to simply copy the dimensions from the 10:1 profile and scale them down, again which could probably be done automously.

 

Attaching some examples would be more than helpful, and I'm sure some code could be written from them. There's a paperclip next to a smily face at the top of your forum post window when replying to a thread. You should be able to attach via that.

Link to comment
Share on other sites

right i have started looking into a few of these and straight away i see things that may hinder me.

 

Old format drg sheet has dimensions on "dim" layer.

New style drg sheet has dimensions on "dim's" layer.

 

As the new format has correct line weights and pen settings the old style sheet would need to correspond.

 

On some of the earlier drgs some dimensions have been exploded and the dim lines have been broke.

 

Here are a couple of examples....old style, and new style.

 

Cheers for the advice so far.

 

Oh i have had to purge the new drg sheet so all the pre-set linetypes and blocks will be lost. principal is still there though. And after doing this test drg i realise still a lot of manual work to configure the viewports and dims. cant see any way round that.

A450-C.dwg

New Dwg Sheet.dwg

Link to comment
Share on other sites

Thanks for the answers patrick, my french is not so good so i might have to get some translation, my lsp knowledge is also very little. I will see what i can do with those. Thanks very much.

 

Lee

Link to comment
Share on other sites

My English is poor too. :oops:

The goal is not to translate the lisp, but to understand the use of objectdbx to respond to your request

 

You two examples.

 

@+

Link to comment
Share on other sites

Woo, sorry about the delay there, my colleague and I are working on an Excel LISP as well as.. well, actual work :P

 

I couldn't create a magical "do everything for you" LISP, but I did work out some things that should save some time.

 

; Coba utilities
; by Mark Mercier, 04-30-09
(defun c:cobaGet()
 (getBlkAttsFile "C:\\ttlblk.txt")
 (copyMSpace)
 )

(defun c:cobaPut()
 (giveBlkAtts)
 (pasteMSpace)
 )

(defun copyMSpace( / ss)
 (if (setq ss (ssget "X" (list (cons 410 "Model") (cons 2 "IPCSHT")))) (command "erase" ss ""))
 (if (setq ss (ssget "X" (list (cons 410 "Model") (cons 2 "DRGSHEET")))) (command "erase" ss ""))
 (command "copyclip" (ssget "X" (list (cons 410 "Model"))) "")
 (command "undo" 2)
 (princ)
 )

(defun pasteMSpace()
 (setvar "tilemode" 1)
 (command "pasteclip" (list 0 0 0))
 )

(defun getBlkAttsFile(file / ent file)
 (setq ent (car(entsel)))
 (setq file (open file "W"))
 (if (= (cdr (assoc 66 (entget ent))) 1)
   (progn
     (setq ent (entnext ent))
     (while (/= (cdr (assoc 0 (entget ent))) "SEQEND")
       (if ent (write-line (strcat (cdr (assoc 2 (entget ent))) "\n" (cdr (assoc 1 (entget ent)))) file))
       (setq ent (entnext ent))
       )
     )
   )
 (close file)
 (princ)
 )

(defun giveBlkAtts( / )
 (setq getFrm (open "C:\\ttlblk.txt" "R"))

 (setq linChk 1)
 (while linChk
   (if (and (setq line1 (read-line getFrm))
        (setq line2 (read-line getFrm))
        )
     (progn
   (setq ssAtBk (ssget "X" (list (cons 66 1))))
   (setq ssVar 0)
   (repeat (sslength ssAtBk)
     (setq getBkN (ssname ssAtBk ssVar))
     (setq ent (entnext getBkN))
     (while (/= (cdr (assoc 0 (entget ent))) "SEQEND")
       (setq attLst (entget ent))
       (if (= (cdr (assoc 2 attLst)) line1)
         (progn
         (princ line2)
           (setq attLst (subst (cons 1 line2) (assoc 1 attLst) attLst))
           (entmod attLst)
           (entupd ent)
       )
         )
       (setq ent (entnext ent))
       )
     (setq ssVar (1+ ssVar))
     )
   )
     (setq linChk nil)
     )
   )

 (close getFrm)
 (princ)
 )

 

I'm assuming you have a lot of files and a template, or at least some other new file to put all the data from the old one into.

 

Once you've saved and loaded the code I just posted, open the old file, and run "COBAGET". This will copy some stuff to your clipboard, as well as create a text file in your "C:\" directory.

 

Open up your new file, where you want to put everything, and run "COBAPUT". This -should- paste a bunch of stuff into your Modelspace and update a lot of information in your title blocks. I'm not sure if it'll get everything or even if it'll work properly, as I'm not at your terminal and all that jazz. But, hopefully, the magic of LISP will shine through.

 

Let me know if it works, or even if it saves some time ^^

Link to comment
Share on other sites

Woo, sorry about the delay there, my colleague and I are working on an Excel LISP as well as.. well, actual work :P

 

I couldn't create a magical "do everything for you" LISP, but I did work out some things that should save some time.

 

; Coba utilities
; by Mark Mercier, 04-30-09
(defun c:cobaGet()
 (getBlkAttsFile "C:\\ttlblk.txt")
 (copyMSpace)
 )

(defun c:cobaPut()
 (giveBlkAtts)
 (pasteMSpace)
 )

(defun copyMSpace( / ss)
 (if (setq ss (ssget "X" (list (cons 410 "Model") (cons 2 "IPCSHT")))) (command "erase" ss ""))
 (if (setq ss (ssget "X" (list (cons 410 "Model") (cons 2 "DRGSHEET")))) (command "erase" ss ""))
 (command "copyclip" (ssget "X" (list (cons 410 "Model"))) "")
 (command "undo" 2)
 (princ)
 )

(defun pasteMSpace()
 (setvar "tilemode" 1)
 (command "pasteclip" (list 0 0 0))
 )

(defun getBlkAttsFile(file / ent file)
 (setq ent (car(entsel)))
 (setq file (open file "W"))
 (if (= (cdr (assoc 66 (entget ent))) 1)
   (progn
     (setq ent (entnext ent))
     (while (/= (cdr (assoc 0 (entget ent))) "SEQEND")
       (if ent (write-line (strcat (cdr (assoc 2 (entget ent))) "\n" (cdr (assoc 1 (entget ent)))) file))
       (setq ent (entnext ent))
       )
     )
   )
 (close file)
 (princ)
 )

(defun giveBlkAtts( / )
 (setq getFrm (open "C:\\ttlblk.txt" "R"))

 (setq linChk 1)
 (while linChk
   (if (and (setq line1 (read-line getFrm))
        (setq line2 (read-line getFrm))
        )
     (progn
   (setq ssAtBk (ssget "X" (list (cons 66 1))))
   (setq ssVar 0)
   (repeat (sslength ssAtBk)
     (setq getBkN (ssname ssAtBk ssVar))
     (setq ent (entnext getBkN))
     (while (/= (cdr (assoc 0 (entget ent))) "SEQEND")
       (setq attLst (entget ent))
       (if (= (cdr (assoc 2 attLst)) line1)
         (progn
         (princ line2)
           (setq attLst (subst (cons 1 line2) (assoc 1 attLst) attLst))
           (entmod attLst)
           (entupd ent)
       )
         )
       (setq ent (entnext ent))
       )
     (setq ssVar (1+ ssVar))
     )
   )
     (setq linChk nil)
     )
   )

 (close getFrm)
 (princ)
 )

 

I'm assuming you have a lot of files and a template, or at least some other new file to put all the data from the old one into.

 

Once you've saved and loaded the code I just posted, open the old file, and run "COBAGET". This will copy some stuff to your clipboard, as well as create a text file in your "C:\" directory.

 

Open up your new file, where you want to put everything, and run "COBAPUT". This -should- paste a bunch of stuff into your Modelspace and update a lot of information in your title blocks. I'm not sure if it'll get everything or even if it'll work properly, as I'm not at your terminal and all that jazz. But, hopefully, the magic of LISP will shine through.

 

Let me know if it works, or even if it saves some time ^^

 

Many thanks for the reply, as per your instructions I got the following from the lisp. (copied from command window).

 

cobaget;

 

Select object: M.GOODWIN

L. GREASLEY

2.5:1

2.5:1

DRG

A107

DESCRIPTION

ARROWHEAD CUTOUT DETAIL

COBA

VARIOUS

MM

mm

K.D.READ

K. D. READ

MATERIAL

SEE A100

BLACK/GREY

SEE A100

DIE

; error: bad argument type: streamp nil

Command:

 

cobaput;

 

coba.lsp successfully loaded.

 

Command:

Command:

Command: cobaput

; error: bad argument type: FILE nil

Command:

 

I could see the attribute results in the command window which is what im looking for.

 

Also need to try and get actual size profile into NEW Drgsheet modelspace. After sitting down with them today i have set up the sheet now so all paper tabs have viewports/pens layers etc right. I even set up a centre point for the profile to hit, which would mean each sheet would have the profile nice and central. Again I purged it out so all layers wont be correct.

 

Was thinking earlier could it be possible to open up each file in the directory a101-a, 102-c, etc a456-f (all random revisions) then create a new drawing (from new coba template) and call it a101-a*??

 

really need to start back up with lisps, only really done a couple of simple ones and that was way back in early nineties :oops:

 

Cheers

 

Lee

Link to comment
Share on other sites

Alright, I ruined my code in order to try to reproduce the error that you got, lo and behold, I believe my first guess was the right one. I don't think you have a C:\ directory ^^'

 

Try replacing the code with this:

(defun c:cobaGet()
 (getBlkAttsFile "Y:\\ttlblk.txt")
 (copyMSpace)
 )

(defun c:cobaPut()
 (giveBlkAtts "Y:\\ttlblk.txt")
 (pasteMSpace)
 )

(defun copyMSpace( / ss)
 (if (setq ss (ssget "X" (list (cons 410 "Model") (cons 2 "IPCSHT")))) (command "erase" ss ""))
 (if (setq ss (ssget "X" (list (cons 410 "Model") (cons 2 "DRGSHEET")))) (command "erase" ss ""))

 (command "copyclip" (ssget "X" (list (cons 410 "Model"))) "")
 (command "undo" 2)
 (princ)
 )

(defun pasteMSpace()
 (setvar "tilemode" 1)
 (command "pasteclip" (list 0 0 0))
 )

(defun getBlkAttsFile(file / ent file)
 (setq ent (car(entsel)))
 (setq file (open file "W"))
 (if (= (cdr (assoc 66 (entget ent))) 1)
   (progn
     (setq ent (entnext ent))
     (while (/= (cdr (assoc 0 (entget ent))) "SEQEND")
       (if ent (write-line (strcat (cdr (assoc 2 (entget ent))) "\n" (cdr (assoc 1 (entget ent)))) file))
       (setq ent (entnext ent))
       )
     )
   )
 (close file)
 (princ)
 )

(defun giveBlkAtts(file / getFrm linChk line1 line2 ssAtBk ssVar getBkN ent attLst)
 (setq getFrm (open file "R"))

 (setq linChk 1)
 (while linChk
   (if (and (setq line1 (read-line getFrm))
        (setq line2 (read-line getFrm))
        )
     (progn
       (setq ssAtBk (ssget "X" (list (cons 66 1))))
       (setq ssVar 0)
       (repeat (sslength ssAtBk)
         (setq getBkN (ssname ssAtBk ssVar))
         (setq ent (entnext getBkN))
         (while (/= (cdr (assoc 0 (entget ent))) "SEQEND")
           (setq attLst (entget ent))
           (if (= (cdr (assoc 2 attLst)) line1)
             (progn
               (setq attLst (subst (cons 1 line2) (assoc 1 attLst) attLst))
               (entmod attLst)
               (entupd ent)
               )
             )
           (setq ent (entnext ent))
           )
         (setq ssVar (1+ ssVar))
         )
       )
     (setq linChk nil)
     )
   )

 (close getFrm)
 (princ)
 )

And where you see "Y:\ttlblk.txt", just replace the "Y:\" portion with some directory of your choosing, in both locations. Let me know if that works. And yeah, I did make some edits elsewhere, so just copy the whole code.

 

Also note the double-backslash. In AutoCAD, a backslash indicates usage of a control code, such as "\n" for a carriage return. As such, you can't just throw in a backslash otherwise AutoCAD will think you're using a control code.. so if you want a backslash, you need to use it twice, "\\". Don't forget that when typing the file path.

 

As for creating new files, yes, that can be done, through a myriad of ways, from .bat files to copy-paste. I just whipped this up now, I think it's pretty sweet:

 

(defun c:cfdir( / )
 (vl-load-com)
 (setq filExt ".dwg")
 (setq filApp "_new")
 
 (setq getDir (vl-filename-directory (getfiled "Select file.." "" "" 32)))
 (setq getFil (vl-directory-files getDir (strcat "*" filExt) 1))
 (foreach filVar getFil
   (vl-file-copy (strcat getDir "\\" filVar) (strcat getDir "\\" (substr filVar 1 (- (strlen filvar) 4)) filApp filExt) T)
   )
 (princ)
 )

Note that this will work for any filetype that you want to specify. Just edit the two variables that you see (remember to keep them in quotes) to indicate what the filetype and what will be appended to the new filename. There's no check for if you input a null string (""), so.. er.. don't do that >.>' Also, you gave an asterisk.. not sure if that was indicating that you wanted 'something' or that you actually wanted an asterisk.. as far as I know, an asterisk is not valid for a filename, so don't use it in here either. Or any other invalid characters. .... I really should have written some checks into this. Oh well. Maybe some other day.

 

Again, let me know if it works out for you. ^^

Link to comment
Share on other sites

good morning freerefill, and many many thanks for the code.

 

Woke up this morning first thing to see you had posted it. Gave it a quick trial at home and it is nearly there. Was only a couple of attribute fields it never filled in. (drg title was one of them).

 

I only have the 09 LT version to hand here at the office so when i get back tonight i will have another play with it.

 

I never got a chance to test the other program this morning but im looking forward to trying it out this evening on my return to home.

 

Thanks a million for helping me out. Will save me hundreds of hours in data entry.

 

Have a great friday!!

Link to comment
Share on other sites

I'm very glad it worked out for you. It's good to know I'm not completely useless. ^.^

 

And yea, it won't catch all the title block attributes. Basically, each attribute has a name and a value. The name is.. sort of like the prompt you see when you edit it, and the value is what you actually specify for the.. well, value. If one title block attribute has a name of "SHEET_TITLE" with the value "Doohicky Widget", and the title block you're trying to populate has an attribute with the value "TITLE", the program will not populate that space. I noticed a few discrepancies between the two title blocks, but fortunately, not many at all. I'm sure the better way to have done it would be to have gone through and matched them up individually, rather than simply exporting the bulk of them... oh well.

 

I'm sure there's a way to put these two functions into a loop using a script.. it wasn't long ago when someone who was using LT had asked for a similar thing (script-based version of populating a title block), and we did manage to muddle through with some level of success. There's a way to export a file list using a batch file (almost in the exact same way I did it with Visual LISP) and from there you can write that data to a script file... ah, but no, you'd still need to run the LISP on all of them, so I guess that wouldn't work.

 

At any rate, I am glad it's working. If you have any questions, suggestions, comments, criticisms, chocolate or delicious cake, I'm sure to be very receptive. Especially for the last two.

Link to comment
Share on other sites

can certainly provide you with the latter two if it saves me time lol,

 

is there any way of "snatching" the model profile (Actual Size) and dropping it in the model view of the new sheet?

 

Again would save me a tremendous amount of time. (got a cheeky streak in me too). Appreciate you are more than busy so if you dont get time no worries. Again cheers for the help.

 

Lee

Link to comment
Share on other sites

and reading back through your last comment, the bullk attributes are fine, can always change the new sheet so the attributes are word for word. ;-)

 

Cheers and have a great weekend

Link to comment
Share on other sites

Right now, the code is set up to grab everything from Modelspace with the exception of... what looks like the two title blocks or borders you have. It should take everything else. It's basically copy-paste, there shouldn't be any difference. If you want, you can knock off the two "IF" statements in the (copyMSpace) function, so that it looks like this:

 

(defun copyMSpace( / )
 (command "copyclip" (ssget "X" (list (cons 410 "Model"))) "")
 (princ)
 )

 

Doing that, it should get everything on Modelspace, including the title blocks. You'd just have to delete what you don't need later.

 

Again, if it isn't getting something, the only thing I could think is that it's on an off, frozen or locked layer. If that's the case, it would be easy to incorporate a fix for that within the code.

 

And I'll be expecting that chocolate and cake soon.... >.>'''

Link to comment
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
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...