Jump to content

Lisp Routine help please


AGC

Recommended Posts

Hi there

 

I need some help please for the UTB lisp routine from Lee Mac. ( to update title block via excel sheet)  Or perhaps point me in the right direction? I'm trying to learn to how write or modify lisp routines

 

I'd like to create a lisp routine  -or to modify the lisp routine I got- so that it looks for only the last 5 drawing revisions and uses those to populate the revision block in the DWG.

 

I have used the UTB with great success, but have not been able to figure out how to automatically organize and clean up the revision block when we get more than 5 revisions (via the spreadsheet or the lisp). If anyone knows to to do that ,please just let me know, this would be a very valuable addition to our workflow.

 

Thanks

Amy

Link to comment
Share on other sites

Think you need to provide some sample data like your titleblock and the format of your revisions. Generic wise you would put all revisions in a list , then sort this list and write the last five back to your title block. Never used Lee's program so you could contact him on his site and maybe he can help you out.

Edited by rlx
Link to comment
Share on other sites

You can read from excel direct rather than say making a CSV then reading that. Re more than 5 revisions yes can be done where you rearrange the revisons removing the 1st and bumping the others down one. Then you can add the new 5th revision.

 

Like rlx need samples.

 

Link to comment
Share on other sites

Thanks for replying..

@BIGAL this is what I have been doing so far, I'm trying to modify it to do that automatically instead of manually

@rlxI did try to reach out to Lee, I thought maybe someone out there had the same challenge.. 

 

Link to comment
Share on other sites

On 11/20/2022 at 12:00 AM, BIGAL said:

You can read from excel direct rather than say making a CSV then reading that. Re more than 5 revisions yes can be done where you rearrange the revisons removing the 1st and bumping the others down one. Then you can add the new 5th revision.

 

Like rlx need samples.

 

 

Do you have (a link to) a good example of code that reads Excel files?

Link to comment
Share on other sites

Ok I have and happy to provide what you want and yeah there is a BUT, the way it works is to take your title block revisions and organise them in row sequence.

 

At moment it is a bit all over the place when looking for correct attribute.

 

There is a very simple method when looking  at block attributes that you get the attributes in a saved order so it is simple to just drop say the A row and replace with the next row a move down this makes the top row empty and can now be filled in.

 

One of the features of bedit is that you can reorder the attributes so for me would have the revs filling in each row before moving onto next row when you edit the attributes.

 

This is what I had in mind for filling in the atts by order.

image.png.2bb1d4ba9e17649de057ecc25d695875.png

 

To edit the revs finding each tagname would be a big task as even the tag names are not similar, eg REV1 = A REV2 =B and so on could look for "REVX" if similar.

 

So in finishing up if your happy to redo the attribute order then I can provide an answer to the cad part. "Move rev up when full.lsp" Should be able to do the excel bit direct (defun getrangexl2 ( / lst UR CR RADD ) a defun that lets you pick a range from excel which would be the new revision details picking relevant cells then updates CAD dwg.

 

 

 

Edited by BIGAL
Link to comment
Share on other sites

if it's just cleaning up your title block you might consider code below (minimal tested) else follow advise from Bigal.

 

(defun c:tst ( / ss ttb sel ent all-rev-list )
  (cond
    ;;; first see if titleblock is present
    ((not (tblsearch "block" "TITLEBLOCK"))
     (princ "\nComputer says no : block 'TITLEBLOCK' not found in this drawing")(setq ttb nil))
    ;;; see if there's more than one , if ony one , use it
    ((and (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 "TITLEBLOCK")))) (= 1 (sslength ss)))
     (setq ttb (ssname ss 0)))
    ;;; if there are more , pick it manualy
    ((not (and (setq sel (entsel "\nMore than one titleblock were found, please select the correct one"))
               (eq "INSERT" (cdr (assoc 0 (setq ent (entget sel))))) (wcmatch (strcase (cdr (assoc 2 ent)) t) "*titleblock*")))
     (princ "\nComputer says no : block 'TITLEBLOCK' not found in this drawing")(setq ttb nil))
    (t (setq ttb nil))
  )
  (if ttb
    (progn (read_revisions)(sort_revisions)(write_revisions)(princ "\nTitleblock updated"))
    (princ "\nComputer says no : sorry no titleblock were updated")
  )
  (princ)
)

(defun read_revisions ( / i rev )  (setq i 64)
  (princ "\nReading revisions")
  (repeat 20
    (if (not (void (setq rev (tai ttb (chr (setq i (1+ i)))))))
      (setq all-rev-list
             (cons
               (cons rev (mapcar '(lambda (x)(tai ttb (strcat rev x))) '("DATE" "DESC" "DES" "DRN" "CHK" "APD")))
               all-rev-list)))
  )
)

(defun sort_revisions ( / )
  (princ "\nSorting revisions")
  (if (vl-consp all-rev-list)
    (setq all-rev-list (vl-sort all-rev-list (function (lambda (a b)(< (strcase (car a))(strcase (car b))))))))
)

(defun wipe_revisions ( / i l r a)
  (princ "\nwiping revisions")
  (setq i 64 l '("DATE" "DESC" "DES" "DRN" "CHK" "APD"))
  (repeat 20
    (setq r (chr (setq i (1+ i))))
    (wai "titleblock" r "")
    (foreach a l (wai ttb (strcat r a) ""))
  )
)


(defun write_revisions ( / l i atl)
  (wipe_revisions)
  (princ "\nWriting revisions")
  ;;; list shoud be sorted from A-Z (no empty revs in list)
  (if (vl-consp all-rev-list)
    (progn
      ;;; only need last 5
      (setq l (last_five all-rev-list) i 64 atl '("DATE" "DESC" "DES" "DRN" "CHK" "APD"))
      (repeat (length l)
        (setq rev (chr (setq i (1+ i))) row (car l) l (cdr l))
        ;;; write revison letter from list
        (wai ttb rev (car row))
        ;;; write rest of values
        (mapcar '(lambda (a v)(wai ttb (strcat rev a) v)) atl (cdr row))
      )
    )
  )
)

;;; a couple of little helper routines

(defun void (x)(or (not x)(= "" x)(and (listp x)(not (vl-consp x)))
  (and (eq 'STR (type x)) (not (vl-remove 32 (vl-string->list x))))))

(defun wai (blk tag val)
  (setq tag (strcase tag) blk (ent->vla blk)) (if blk (vl-some '(lambda (x)(if (= tag (strcase (vla-get-tagstring x)))
    (progn (vla-put-textstring x val) val))) (vlax-invoke blk 'getattributes))))

(defun tai ( blk tag )
  (setq tag (strcase tag) blk (ent->vla blk)) (if blk (vl-some '(lambda (x) (if (= tag (strcase (vla-get-tagstring x)))
    (vla-get-textstring x))) (vlax-invoke blk 'getattributes))))

(defun ent->vla ( e / ss )
  (cond
    ((= (type e) 'VLA-OBJECT) e)
    ((= (type e) 'ENAME)(vlax-ename->vla-object e))
    ((and (= (type e) 'STR) (tblsearch "block" e)(setq ss (ssget "x" (list (cons 0 "INSERT")(cons 2 e))))) (ent->vla (ssname ss 0)))
    (t nil)
  )
)

(defun last_five ( l / r)
  (cond
    ((not (vl-consp l))(setq r nil))
    ((< (length l) 5) (setq r (reverse l)))
    (t (setq l (reverse l)) (repeat 5 (setq r (cons (car l) r))(setq l (cdr l))))
  )
  r
)

; (c:tst)

 

🐉

Link to comment
Share on other sites

Looking at the excel yes look at cells in Y range starting at Cell Y6 look for whether there are revisions at those cells. So a "H" would imply 8 revisions so read next 5 * 7 cells starting at rev "D" so "AU6" then update title block also matching the layout name. This can be done. A bit of programming time and testing. It may be combine what rlx has done with a read excel direct. Same idea rub out all revs and update.

 

Thinking aloud a real quick and dirty is move the revs details down but remove all the details so say revs A-C no longer appear. Will have a look at that also. 

 

 

Link to comment
Share on other sites

Thinking again can do REVA, REVB as "A" is (chr 65) so (strcat "REV" (CHR X)) then use set, read, eval etc

 

When you look at the block the att order is all over the place, go next and at times does not go to next attribute but rather goes down a line. 

 

On the to do list real work to do 1st.

 

Link to comment
Share on other sites

@bigal : your approach has one downside , well , for me anyway : if yóu can change the order of attributes , so can someone else. At my company we have lots of old & new titleblocks , dozens and dozens actually , so controlling them is a challenge on its own to say the least. But one of my favorite scenarios is the one where document control checks out a bunch of drawings to a third party but when we get them back (often looking ok on the outside) our document control system suddenly can't read them anymore. Sometimes the contractor only changed the logo or the name of the titleblock, or like today , all the attribute names were changed to 'Eplan standard'. And then : who you're gonna call? Ghostbusters! , oh , sorry , wrong universe... me me me , its me!


I have complained about this issue more than once in the past, how contractors should not change our titleblocks. Sometimes it helped for a while but this was often just for so long and then the circus started all over again. So just wrote a routine where I link the attribute names of the divergent titleblock with the attribute names of our 'standard' (= latest) titleblock and connect them through a couple of generic variable names like ((main-rev our-attribute-name their-attribute-name)...)


Then it's just a matter of read the relevant attributes from the divergent titleblock and ditch it and then insert our latest titleblock and write back and / or compliment the values. Sometimes also need do a little finetuning like resizing / text styles / linetypes , moving stuff a little etc.


That way , next time somebody messes up (intentionally or not) our titleblock I only need to change a few attribute names in my link list and the show can go on again. I know , nobody should experiment on our titleblocks but it happens. So I can cry about it or deal with it (and bill them for it...you want a new coat baby? daddy will get you a new coat)


Also in my case, I'm not always involved in all the projects going on, so the whole document control thing happens without me. I'm only the poor dragon who can clean up the mess months or even years after the project has already finished while the contractor is laying on a beach in a galaxy , far far away...


If your drawings never leaves your company , attribute order can work but sadly I just don't have this luxury. Also, company may already have thousand and thousands of drawings, are you gonna replace all the titleblocks for just 1 routine?


So peoples of this earth, thats why me , myself & I prefer to rely on attribute names rather than their order.


oh , thank you , thank you

 

🐉

 

Edited by rlx
Link to comment
Share on other sites

rlx you are right the main issue is how well the excel update and update cad are carried out, like wise from a programming point of view it is a time thing, can read all the values from excel and update. Can read the tagnames from excel as you have suggested. 

 

But what happens if someone just updates the dwg only the plans must go out NOW the boss is shouting and it is the wife's birthday so have to go ASAP. No excel update.

 

Looking at the excel it can be done it's just a matter of reading all the correct cells, for me reading a csv is too hard as I have gone more to read direct. Where to start maybe just at E6 then get E7, E8 etc, stop when the next cell is blank. 

 

A question to AGC, can each layout have a different set of revisions ? Looking at the excel is there only 1 layout for a dwg, we worked 1 dwg, multiple layouts. Makes a difference.

 

This is looking like a Beer money task. 

 

 

Edited by BIGAL
Link to comment
Share on other sites

Kinda depends on the type and level of OP's document control system (if any). Reading & writing xls is relatively straightforward. When reading from xls I once tried to check every line until I found the target I needed. This was as slow as my granny. So went from granny to wife mode and changed it to swallow the whole thing in one go and put it in a assoc list. No problem for a list with only a couple of thousand lines. But if we are talking about tens of thousands of records you either break up in multiple smaller files, one for each area or building whatever , or grow up and buy a decent document control program.

 

As far as I see it , OP only requested a way to clean up the titleblock for which I provided a possible solution , if he wants more OP may buy you a nice big cool beer bigal 🍻

Link to comment
Share on other sites

Thanks rlx need to wait for AGC before do any more. Could do a macro in excel add new revision and its added to correct dwg layout. Excel controlling, not something I have done other than draw objects from excel. 

Edited by BIGAL
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...