Code change request

Code change request

zac_bullock
Enthusiast Enthusiast
1,658 Views
21 Replies
Message 1 of 22

Code change request

zac_bullock
Enthusiast
Enthusiast

Hello again, I have recently been making changes to my companies outdated Lisp files. The one attached below asks for "Left, Center" Justification for 6 Columns for Text. As I am not a coder (yet) I need some help taking this Justification option out! There is no need to type, as the option I choose is always center. I don't want the keyword option at all, I would just like to be able to click 6 times in a row and the program just work. Thank you in advance to anyone who has the time to take a look at this for me!

0 Likes
Accepted solutions (2)
1,659 Views
21 Replies
Replies (21)
Message 2 of 22

komondormrex
Mentor
Mentor
Accepted solution

hi,

without testing

(defun charterr (x / msg)
      (setq *error* olderr) 
      (if cmd (setvar "CMDECHO" cmd))
      (if unt (setvar "LUNITS" unt))
      (if snp (setvar "OSMODE" snp))
      (if blp (setvar "BLIPMODE" blp))
      (command-s "COLOR" "bylayer")
      (setq msg (strcat "Error " x " detected...aborting"))
      (prompt msg)  
      (if lyr (command-s "-layer" "s" lyr ""))
      (close flo)
      (terpri)
      (exit)
)
(defun mk_s_lyr (nam col lntyp)
    (if (tblsearch "LAYER" nam)
        (command "-layer" "s" nam "")
        (progn
            (command "-layer" "m" nam "")
            (if col (command "c" col nam))
            (if lntyp (command "lt" lntyp nam))
        )
    )
    (princ)
)
(defun rtod (a)
    (* a (/ 180.0 pi))
)
(defun c:chartxt (/ olderr inputf rotagld flo scl temp tempt lncont rotagl stpt nocolu lndist dist1 dist_list ;just1 just_list)
    (setq olderr *error*
        *error* charterr
        cmd (getvar "cmdecho")
        snp (getvar "osmode")
        unt (getvar "lunits")
        lyr (getvar "clayer")
        blp (getvar "blipmode")
        scl (getvar "dimscale")
        lncont 0 inputf "dummy.dum"
        ;just1 nil just_list nil
        dist1 nil dist_list nil
    )
    (setvar "lunits" 2)
    (setvar "cmdecho" 0)
    (setvar "regenmode" 0)
    (setvar "osmode" 1)
    (mk_s_lyr "chart_text" 3 nil)
    (setq sz (* scl 0.08))
    (setq nocolu (getint "\nNumber of Columns in chart? : "))
    (while (= (findfile inputf) nil)
        (setq inputf (getfiled "\nName of text file to Read? (file.ext): " "\\" "" 16))
        (if (= (findfile inputf) nil)
            (progn
                (setq msg1 (strcat "\nInput file < " inputf " > invalid...\nPlease Try Again..."))
                (princ msg1)
            )
        )
    )
    (initget (+ 2 4))
    (setq nolnst (getint (strcat "\nStarting at line number of " inputf " <1>: ")))
    (if (or (= nolnst "") (= nolnst nil))
        (setq nolnst 0)
    )
    (initget 6 "All")
    (setq noflr (getint "\nNumber of Lines to Read? <All>: "))
    (if (or (= noflr nil) (= noflr "") (= noflr " "))
        (setq noflr "ALL")
    )
    (if (>= nocolu 1) 
        (progn
            ;(initget 1 "Left Center")
            ;(setq just1 "Center");(getkword "\nJustification for column 1. Left/Center: "))
            (initget 1)
            (setq stpt (getpoint "\nFirst column text start point: "))
            (initget 1)
            (setq lndist (getdist stpt "\nPick point or Distance between lines: "))
            (initget 1)
            (setq rotagl (getangle stpt "\nRotation angle for text? "))
            (if (= rotagl 0)
                (setq rotagld 0)
                (setq rotagld (rtod rotagl))
            )
        )
    )
    (if stpt;(and just1 stpt)
        (setq ;just_list (cons just1 just_list)
            dist_list (cons stpt dist_list)
            tempt stpt
        )
    )
    (repeat (- nocolu 1) 
        ;(initget 1 "Left Center")
        ;(setq just1 "Center");(getkword "\nJustification for next column. Left/Center: "))
        (initget 1)
        (setq dist1 (getpoint tempt "\nPick point for next column text: "))
        (setq ;just_list (cons just1 just_list)
            dist_list (cons dist1 dist_list)
            tempt dist1
        )
    )
    (if (findfile inputf)
        (progn
            (setq flo (open inputf "r"))
            (if (> nolnst 1)
                (progn 
                    (setq nolnst (* (- nolnst 1) nocolu))
                    (repeat nolnst (setq temp (STRCASE (read-line flo))))
                )
            )
            (setq temp (STRCASE (read-line flo))
                loop 0 
                dist_list (reverse dist_list)
                ;just_list (reverse just_list)
            )
            (if (or (= noflr "") (= noflr "A") (= noflr "All") (= noflr "ALL"))
                (while temp
                    (while (and temp (>= (- nocolu 1) loop))
                        (setq tempt (polar (nth loop dist_list) (- rotagl (* 0.5 pi)) (* lncont lndist))
                            ;just1 (nth loop just_list)
                        )
                        ;(if (= just1 "Center")
                            (if (and (/= temp "")(/= temp nil))
                                (command ".text" "C" tempt sz rotagld temp)
                            )
                            ;(if (and (/= temp "")(/= temp nil))
                            ;    (command ".text" tempt sz rotagld temp)
                            ;)
                        ;)
                        (setq temp (strcase (read-line flo))
                            loop (1+ loop)
                        )
                    )
                    (setq           ;;;;stpt (polar stpt (- rotagl 1.5707963) lndist)
                        lncont (+ lncont 1)
                        loop 0
                    )
                )
                (while (and (> noflr lncont) temp)
                    (while (and temp (>= (- nocolu 1) loop))
                        (setq tempt (polar (nth loop dist_list) (- rotagl (* 0.5 pi)) (* lncont lndist))
                            ;just1 (nth loop just_list)
                        )
                        ;(if (= just1 "Center")
                            (if (and (/= temp "")(/= temp nil))
                                (command ".text" "C" tempt sz rotagld temp)
                            )
                            ;(if (and (/= temp "")(/= temp nil))
                            ;    (command ".text" tempt sz rotagld temp)
                            ;)
                        ;)
                        (setq temp (strcase (read-line flo))
                            loop (1+ loop)
                        )
                    )
                    (setq ;;;;;;;;stpt (polar stpt (- rotagl 1.5707963) lndist)
                        lncont (+ lncont 1)
                        loop 0
                    )
                )
            )
            (close flo)
            (princ)
        )
    )
    (princ)
)
0 Likes
Message 3 of 22

zac_bullock
Enthusiast
Enthusiast

Thanks so much! Works like a charm.

0 Likes
Message 4 of 22

Sea-Haven
Mentor
Mentor

 Is the text file just 1 column of numbers ? You may be able to remove some steps, need a text file to look at and final result dwg or image. You can read how many characters are in a string so work out the column spacing with no user interaction.

0 Likes
Message 5 of 22

zac_bullock
Enthusiast
Enthusiast

No, the excel file is 6 columns, and I have to copy that data into Microsoft Word, and save as a plain text file, and select line breaks. Only then will it come in how I need it to. There is a very long process that my company has implemented, and most drafters do the process the manual way, I am trying to find more efficient ways to get the job done and with less errors!

0 Likes
Message 6 of 22

Sea-Haven
Mentor
Mentor

So you want a Excel to a table, or  columns of texts, Post the excel file you can read Excel direct from CAD. Post a sample dwg as well.

0 Likes
Message 7 of 22

zac_bullock
Enthusiast
Enthusiast

Hi Sea-Haven,

 

This process is somewhat convoluted, and I will do my best to explain it:

We receive "cable pull" drawings, essentially all existing cables in a sub. Our client wants to add more cables to this drawing, and they have a certain table block that they want us to use. These new cables have to be sorted into the existing cables, and sometimes the style of the table needs to be updated. The best thing I use is the "TableBuilder" Command, it allows me to export the existing cables to excel, where I can sort the new cables in. The issue is bringing these cables back into CAD in the predefined tables. That is where the CHARTXT tool comes in. I can select column points and set a height and the information WILL come in correct, but there are no spaces as shown in the updated drawing.

Anyways, I know there are better ways to do all of this and there are some more caveats of course. I've pasted the original dwg we get from the client, and the updated that we send back. I've also pasted the Excel file with all combined, and the plain text file that will be read into CAD.

 

Thank you for your interest and help so far!

 

 

0 Likes
Message 8 of 22

Sea-Haven
Mentor
Mentor

had a look and yes can be done as a Table much easier to make and a better CAD object than lines and text you can split a table into say 3 columns or a single big one.

 

One enhancement is need excel to have blank rows so they are duplicated in the table.

 

Adding the check is common item may be difficult as 1 column compare 3 characters "140xxx" but another is 2 characters "49xxx".

 

Its on my to do list.

0 Likes
Message 9 of 22

komondormrex
Mentor
Mentor

and in what form do you get the info on cables to add to the existing table?

0 Likes
Message 10 of 22

zac_bullock
Enthusiast
Enthusiast

"can be done as a Table much easier to make and a better CAD object than lines and text"

I have messed around with the table, I even have a table already with the exact sized columns and rows, all the fonts are correct. BUT - pretty often there are cables that have "from" and "to" data, and sometimes "size" data that are longer than what the table provides, in which case the text wraps to the next line. I tried to navigate that problem by creating a new text style with a .8 width factor, but it is MASSIVELY lag inducing on my work laptop to change the width factor on the individual cells. Just when I thought I had come up with a good idea 😀

 

"One enhancement is need excel to have blank rows so they are duplicated in the table." - Yes, that would be ideal. Unfortunately, the excel code that I use to sort does not retain any spaces from existing data. I don't know maybe there is a solution out there for that.

0 Likes
Message 11 of 22

zac_bullock
Enthusiast
Enthusiast

They come to me as an excel file, the font is off but is easily changed. They only give me the new cables though, and I have to manually sort them into the old data.

0 Likes
Message 12 of 22

komondormrex
Mentor
Mentor

for that lengthy kind of table you have selected reasonably smart solution, otherwise you will endlessly be at struggle with autocad tables. and sure that solution prevents you from quick adjustment and the whole table should be revised and redrawn imho. what would i do in your position are:

1. split you 3 part block to 1, which may be drawn with one lisp code with defined parameters of columns and rows.

2. upon receiving regular changes get the old data, combine it with changes and draw and fill the needed number of cable blocks with sorted combined data using same one lisp from item 1.

0 Likes
Message 13 of 22

zac_bullock
Enthusiast
Enthusiast

I'm sorry I did not follow your points. When you say "split your 3 part block to 1", do you mean the tables themselves? If this is what you mean, wouldn't it be easier to just have a block and continue using the process I have been on? I am confused on what the lisp code would be doing in this instance?

0 Likes
Message 14 of 22

komondormrex
Mentor
Mentor

your table block consists of 3 independent tables, so i meant it would be better for it to hold only one table. and lisp will insert needed quantity of each table block upon receiving summary cable data.

0 Likes
Message 15 of 22

zac_bullock
Enthusiast
Enthusiast

I understand now, thank you for clarifying. With me bringing over the cables manually anyway, having to separate each series with spaces, I will probably continue doing it the way I am as to not cause confusion for the other designers. (Not everyone cares so much about LISP efficiency as we do!) Thank you for your time and thoughts on this subject.

0 Likes
Message 16 of 22

Sea-Haven
Mentor
Mentor

Here is a excel version I have added spaces in the excel file. Ok to run open the Excel file, then appload the program it will run automatically. A message will appear, press ok then go to the excel and click inside it a prompt select range should appear, you can type A1:F230 or select the range. A table should appear, its very close to what you have now, your home work is to set maximum row so it auto splits. I will see if can do. There is a short delay while it reads the excel. So test by selecting a few rows.

 

SeaHaven_0-1691308772580.png

 

0 Likes
Message 17 of 22

zac_bullock
Enthusiast
Enthusiast

Every time I try to select a range in excel this error message appears in AutoCAD. I could be doing something wrong, my process is - Open Excel workbook with no spaces in it, open drawing, run LSP, specify text height .08, select a point in space, select rows a1:f230 in excel - This gives me this error message

 

zac_bullock_0-1691416872551.png

 

0 Likes
Message 18 of 22

Sea-Haven
Mentor
Mentor

Will double check what is going on ran many times during programming. 

 

This is what I get. for the pick point line of code.

(setq pt1 (vlax-3d-point (getpoint "\nPick point for top left hand of table: ")))
Pick point for top left hand of table: #<variant 8197 ...>

0 Likes
Message 19 of 22

komondormrex
Mentor
Mentor
Accepted solution

hey,

having spent little more time on your subject i want to show you the whole idea in rough outline. so there is a csv file, which has been jumbled and extra blank rows were added. from that csv file a lisp routine draws few tables, sorting chart with data blank line delimiters between series added.

 

0 Likes
Message 20 of 22

Sea-Haven
Mentor
Mentor

"select rows a1:f230" If you type need Caps A1:F230, you can select say A1 then drag selection to F230 it will show that in the selection message, that may have been what was wrong. I will look at the code by Gile it may need a strcase to ensure Capitals are used. 

 

Ok bug 2 it expects that your layers "CHART_TEXT" and "Cables" exist, will add to code a check do they exist. Let me know if working as is.

0 Likes