Jump to content

Extracting Building Dimensions from Text File


Sprunkle

Recommended Posts

I have been using AutoCAD for a long time, but only just recently started learning more about how AutoLISP works. I have been trying to find an answer to my question on my own, but I am afraid I may not know the correct way to ask Google because I am having some trouble.

 

I have a text-based document that is space-delimited that has all the parameters for a building project, and I am wondering how to extract data from this text-based file (building length, width, roof slope, etc.) to use in a LISP program that will draw something based on that data.

 

Any advice or guidance would be appreciated.

 

I'll include what I have so far on the LISP program I am working on that will draw an anchor bolt plan for a metal building. Currently, I just enter the building parameters by typing them in, but I know I can be more efficient.

 


;   the dtr funtion converts degrees to radians
;   the rtd funtion converts radians to degrees
;
(defun dtr (a)(* pi (/ a 180.0))
)
;
(defun rtd (a)(/ (* a 180.0) pi)
)
(defun c:bldg ()
  (prompt "\nBuilding length? ")(setq blength (getdist ""))
  (prompt "\nBuilding width? ")(setq bwidth (getdist ""))
  (prompt "\nRF Offset? ")(setq rfo (getdist ""))
  (prompt "\nBay Spacing #1: ")(setq bay1 (getdist ""))
  (prompt "\nBay Spacing #1 to #2: ")(setq bay2 (getdist ""))
  (prompt "\nBay Spacing #2 to #3: ")(setq bay3 (getdist ""))
  (prompt "\nBay Spacing #3 to #4: ")(setq bay4 (getdist ""))
  (prompt "\nBay Spacing #4 to #5: ")(setq bay5 (getdist ""))
  (prompt "\nBay Spacing #5 to #6: ")(setq bay6 (getdist ""))
  (prompt "\nSheeting notch distance: ")(setq sn (getdist ""))
  (prompt "\nEW Bay Spacing 1: ")(setq ewspc1 (getdist ""))
  (prompt "\nEW Bay Spacing 2: ")(setq ewspc2 (getdist ""))
  (prompt "\nEW Bay Spacing 3: ")(setq ewspc3 (getdist ""))
  (prompt "\nEW Bay Spacing 4: ")(setq ewspc4 (getdist ""))
  (prompt "\nEW Bay Spacing 5: ")(setq ewspc5 (getdist ""))
;
  (setq p1 (getpoint "\nClick a start point: "));origin polar
  (setq p2 (polar p1 (dtr 0) rfo));point along FSW where RF offset line starts
  (setq p3 (polar p1 (dtr 0) bay1))
  (setq p4 (polar p3 (dtr 0) bay2))
  (setq p5 (polar p4 (dtr 0) bay3))
  (setq p6 (polar p5 (dtr 0) bay4))
  (setq p7 (polar p6 (dtr 0) bay5))
  (setq p8 (polar p7 (dtr 0) bay6))
  (setq p100 (polar p1 (dtr 0) (- blength rfo)))
  (setq p200 (polar p1 (dtr 270) sn))
  (setq rf1mid (polar p2 (dtr 90) (/ bwidth 2)))
  (setq rf2mid (polar rf1mid (dtr 0) bay2))
  (setq p300 (polar p1 (dtr 90) ewspc1))
  (setq p301 (polar p300 (dtr 90) ewspc2))
  (setq p302 (polar p301 (dtr 90) ewspc3))
  (setq p303 (polar p302 (dtr 90) ewspc4))
  (setq p304 (polar p303 (dtr 90) ewspc5))
;
  (command "-LAYER" "m" "bldgboundary" "c" "green" "" "l" "continuous" "" "")
  (command "line" p1 "a" "0" blength "a" "90" bwidth "a" "180" blength "c"); draws rectangle of bldg
  (command "-LAYER" "m" "RFlines" "c" "red" "" "l" "centerx2" "" "")
  (command "line" p2 "a" "90" bwidth ""); draws RF lines; put 0 if no more bays
  (command "line" p3 "a" "90" bwidth "")
  (command "line" p4 "a" "90" bwidth "")
  (command "line" p5 "a" "90" bwidth "")
  (command "line" p6 "a" "90" bwidth "")
  (command "line" p7 "a" "90" bwidth "")
  (command "line" p8 "a" "90" bwidth "")
  (command "line" p100 "a" "90" bwidth "")
  (command "-LAYER" "m" "sheetingnotch" "c" "yellow" "" "l" "continuous" "" "")
  (command "line" p200 "a" "0" (+ blength sn) "a" "90" (+ bwidth (* sn 2)) "a" "180" (+ blength (* sn 2)) "a" "270" (+ bwidth (* sn 2)) "c")
  (command "-LAYER" "m" "blocks" "c" "white" "" "l" "continuous" "" "")
  (command "INSERT" "C:/Users/JRS/desktop/lisp/B100504_0.75abolts_3-4-3" p2 "" "" "")
  (command "INSERT" "C:/Users/JRS/desktop/lisp/B100504_0.75abolts_3-4-3" p3 "" "" "")
  (command "INSERT" "C:/Users/JRS/desktop/lisp/B100504_0.75abolts_3-4-3" p4 "" "" "")
  (command "INSERT" "C:/Users/JRS/desktop/lisp/B100504_0.75abolts_3-4-3" p5 "" "" "")
  (command "INSERT" "C:/Users/JRS/desktop/lisp/B100504_0.75abolts_3-4-3" p6 "" "" "")
  (command "INSERT" "C:/Users/JRS/desktop/lisp/B100504_0.75abolts_3-4-3" p100 "" "" "")
  (command "-mirror" "fil" "b" "B100504_0.75abolts_3-4-3" "" rf1mid rf2mid "")
;
   (initget "Hr Cff CFb")
   (setq option1 (getkword "\nEW col#1 type: [Hr/Cff/CFb]:"))
   (cond ((= option1 "Cff")(command "insert" "C:/Users/JRS/desktop/lisp/8x4C_0.625abolts_faceFSW" p300 "" "" ""))
         ((= option1 "CFb")(command "insert" "C:/Users/JRS/desktop/lisp/8x4C_0.625abolts_faceBSW" p300 "" "" ""))
		 ((= option1 "Hr")(command "insert" "C:/Users/JRS/desktop/lisp/w8x10_0.625abolts_lew" p300 "" "" ""))
   )
   (initget "Hr Cff CFb")
   (setq option2 (getkword "\nEW col#2 type: [Hr/Cff/CFb]:"))
   (cond ((= option2 "Cff")(command "insert" "C:/Users/JRS/desktop/lisp/8x4C_0.625abolts_faceFSW" p301 "" "" ""))
         ((= option2 "CFb")(command "insert" "C:/Users/JRS/desktop/lisp/8x4C_0.625abolts_faceBSW" p301 "" "" ""))
		 ((= option2 "Hr")(command "insert" "C:/Users/JRS/desktop/lisp/w8x10_0.625abolts_lew" p301 "" "" ""))
	)
   (initget "Hr Cff CFb")
   (setq option3 (getkword "\nEW col#3 type: [Hr/Cff/CFb]:"))
   (cond ((= option3 "Cff")(command "insert" "C:/Users/JRS/desktop/lisp/8x4C_0.625abolts_faceFSW" p302 "" "" ""))
         ((= option3 "CFb")(command "insert" "C:/Users/JRS/desktop/lisp/8x4C_0.625abolts_faceBSW" p302 "" "" ""))
		 ((= option3 "Hr")(command "insert" "C:/Users/JRS/desktop/lisp/w8x10_0.625abolts_lew" p302 "" "" ""))
	)
   (initget "Hr Cff CFb")
   (setq option4 (getkword "\nEW col#4 type: [Hr/Cff/CFb]:"))
   (cond ((= option4 "Cff")(command "insert" "C:/Users/JRS/desktop/lisp/8x4C_0.625abolts_faceFSW" p303 "" "" ""))
         ((= option4 "CFb")(command "insert" "C:/Users/JRS/desktop/lisp/8x4C_0.625abolts_faceBSW" p303 "" "" ""))
		 ((= option4 "Hr")(command "insert" "C:/Users/JRS/desktop/lisp/w8x10_0.625abolts_lew" p303 "" "" ""))
	)
   (initget "Hr Cff CFb")
   (setq option5 (getkword "\nEW col#5 type: [Hr/Cff/CFb]:"))
   (cond ((= option5 "Cff")(command "insert" "C:/Users/JRS/desktop/lisp/8x4C_0.625abolts_faceFSW" p304 "" "" ""))
         ((= option5 "CFb")(command "insert" "C:/Users/JRS/desktop/lisp/8x4C_0.625abolts_faceBSW" p304 "" "" ""))
		 ((= option5 "Hr")(command "insert" "C:/Users/JRS/desktop/lisp/w8x10_0.625abolts_lew" p304 "" "" ""))
	)
;
  (command "-LAYER" "m" "dims" "c" "cyan" "" "l" "continuous" "" "")
  (command "dli" p2 p3 "@36<270")
  (command "dli" p1 p300 "@36<180")
  (command "-LAYER" "S" "0" "")
 )

 

Thanks!

 

Link to comment
Share on other sites

1 hour ago, SLW210 said:

Where's the text file?

I did not include a text file since I was asking about the process itself. Also, I don't have access to one of the particular files I would use because they are on my work computer. I will give an example of what it is like.

BLDG Data Example.txt

Link to comment
Share on other sites

While I think about all the code a few suggestions.

 

1st up the variable PI is just that a reserved value, (dtr 0) is just that 0.0 (dtr 90) is (/ pi 2) or a better way (setq pi2 (/ pi 2.)), pi is 180 degrees , 270 is (* 1.5 pi) again (setq pi270 (* 1.5 pi)).

eg (setq p300 (polar p1 pi2 ewspc1))

 

image.png.6784edeba905098eaef220f9ad5a4bd8.png

 

This can be replaced by my Multi getvals.lsp which will pop a dcl asking for all the values, if you look at the top of the code there are lots of examples how to use. It will return a list of the values entered. So use say (setq bay2 (atof (nth 4 ans))), you can test it seperate to your code. If you get stuck and want to use it post again.

image.png.b28ac88902930b64ba52c5261e8043cf.pngMulti GETVALS.lsp

 

Or using what you have rearrange the getdist line, no need for prompt.

(setq bay1 (getdist "\nBay Spacing #1: "))

 

 

"C:/Users/JRS/desktop/lisp/B100504_0.75abolts_3-4-3" if you add the path "C:/Users/JRS/desktop/lisp/" to your support paths OPTIONS FILE Support path,  can just use the Block name and dont need the path. "(command "-INSERT" "B100504_0.75abolts_3-4-3" p2 "" "" ""), note also -Insert this stops the dialog popping forcing a command line version of insert. Why not save the bolts in say c:\myblocks rather than desktop. Your lips code in c:\mylisp and so on. In my former employment all these where on a server.

 

Looked at TXT file yes can be read maybe 2 versions manual entry or read a file ? If I can find time busy for next few days some one else may provide some code also, good to see having a go the way to learn.

 

Edited by BIGAL
Link to comment
Share on other sites

Can you post an image at least a dwg would be best as dont know if what is being input is correct. All the values can have  a preset value or can save the default values when used multiple times.

 

 

DCL created from 2 lists and Multi getval 2col.lsp

image.png.c11823b40c41a2581a5768ed35bb99a3.png

 

The bay spacing can be up to 6 bays as a manual input the idea behind the 0 value is that there is no more values so looking at text file it you would do 25 25 25 then 20 20 for EW bay. So correct number of steps are carried out.

 

What other data is in the text file its frustrating when people ask for help then keep coming back with additional requirements rather than a full data list. Hence say a step procedure of a dwg using text file. Show how it would be done manually step by step. So can see values being used.

 

Yes have some code behind this.

 

 

 

Edited by BIGAL
Link to comment
Share on other sites

BIGAL, thanks for the help. I picked up several helpful tips from what you wrote. I actually rewrote what I had since I have AutoCAD at home and ProgeCAD at work and they work differently. Below I will include the code I did for AutoCAD and an image of what it gives me. Until I figure out how to pull in data automatically, I like the dialog box you showed. I will that a look at that more closely when I get a chance.

(defun dtr (x)(* pi (/ x 180.0)))
(defun c:bldg ()
(command "lunits" 4)
(setq rfo (getdist "\nRigid frame offset? "))
(setq bay1 (getdist "\nSW Bay Spacing #1: "))
(setq bay2 (getdist "\nSW Bay Spacing #2: "))
(setq bay3 (getdist "\nSW Bay Spacing #3: "))
(setq ewbay1 (getdist "\nEW Bay Spacing #1: "))
(setq ewbay2 (getdist "\nEW Bay Spacing #2: "))
(setq ewbay3 (getdist "\nEW Bay Spacing #3: "))
(setq sn (getdist "\nSheeting Notch: "))

(setq p1 (getpoint "\nClick a start point: ")); start point at corner of FSW & LEW
(setq p2 (polar p1 (dtr 0) rfo)); RF offset
(setq p3 (polar p2 (dtr 0) (- bay1 rfo))); RFline2 on FSW
(setq p4 (polar p3 (dtr 0) bay2)); RFline3 on FSW
(setq p5 (polar p4 (dtr 0) (- bay3 rfo)))
(setq p6 (polar p5 (dtr 0) rfo)); RFline4 on FSW also REW/FSW
(setq p7 (polar p6 (dtr 90) ewbay1)); REW EWcol line B
(setq p8 (polar p7 (dtr 90) ewbay2)); REW EWcol line C
(setq p9 (polar p8 (dtr 90) ewbay3)); REW/BSW
(setq p10 (polar p9 (dtr 180) rfo))
(setq p11 (polar p10 (dtr 180) (- bay3 rfo))); RFline4 on BSW
(setq p12 (polar p11 (dtr 180) bay2)); RFline3 on BSW
(setq p13 (polar p12 (dtr 180) (- bay1 rfo))); RFline2 on BSW
(setq p14 (polar p13 (dtr 180) rfo)); BSW/LEW
(setq p15 (polar p14 (dtr 270) ewbay3)); LEW EWcol line C
(setq p16 (polar p15 (dtr 270) ewbay2)); REW EWcol line B
(setq p17 (polar p1 (dtr 270) sn))

(command "ltscale" 20)
(command "-LAYER" "m" "bldgboundary" "c" "green" "" "l" "continuous" "" "")
(command "pline" p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 "c")
(setq bline (entlast))
(command "offset" sn bline p17 "")

(command "-LAYER" "m" "RFlines" "c" "red" "" "l" "center" "" "")
(command "line" p2 p13 "")
(setq rfline1 (entlast))
(command "line" p3 p12 "")
(setq rfline2 (entlast))
(command "line" p4 p11 "")
(setq rfline3 (entlast))
(command "line" p5 p10 "")
(setq rfline4 (entlast))

(command "-LAYER" "m" "blocks" "c" "white" "" "l" "continuous" "" "")
(command "INSERT" "B100504_0.75abolts_3-4-3" p2 "" "" "")
(setq bp1 (entlast))
(command "INSERT" "B100504_0.75abolts_3-4-3" p3 "" "" "")
(setq bp2 (entlast))
(command "INSERT" "C:/lisps/B100504_0.75abolts_3-4-3" p4 "" "" "")
(setq bp3 (entlast))
(command "INSERT" "C:/lisps/B100504_0.75abolts_3-4-3" p5 "" "" "")
(setq bp4 (entlast))
(command "INSERT" "C:/lisps/B100504_0.75abolts_3-4-3" "r" "180" p10 "" "")
(setq bp5 (entlast))
(command "INSERT" "C:/lisps/B100504_0.75abolts_3-4-3" "r" "180" p11 "" "")
(setq bp6 (entlast))
(command "INSERT" "C:/lisps/B100504_0.75abolts_3-4-3" "r" "180" p12 "" "")
(setq bp7 (entlast))
(command "INSERT" "C:/lisps/B100504_0.75abolts_3-4-3" "r" "180" p13 "" "")
(setq bp8 (entlast))

(initget "Hotrolled coldformFSW-facing coldformBSW-facing")
(setq ewc1 (getkword "\nEW col#1 type: [Hotrolled/coldformFSW-facing/coldformBSW-facing]:"))
(cond ((= ewc1 "Hotrolled")(command "insert" "C:/lisps/w8x10_0.625abolts_lew" p16 "" "" ""))
      ((= ewc1 "coldformFSW-facing")(command "insert" "C:/lisps/8x4C_0.625abolts_faceFSW" p16 "" "" ""))
      ((= ewc1 "coldformBSW-facing")(command "insert" "C:/lisps/8x4C_0.625abolts_faceBSW" p16 "" "" "")))
(setq bp9 (entlast))

(initget "Hotrolled coldformFSW-facing coldformBSW-facing")
(setq ewc2 (getkword "\nEW col#2 type: [Hotrolled/coldformFSW-facing/coldformBSW-facing]:"))
(cond ((= ewc2 "Hotrolled")(command "insert" "C:/lisps/w8x10_0.625abolts_lew" p15 "" "" ""))
      ((= ewc2 "coldformFSW-facing")(command "insert" "C:/lisps/8x4C_0.625abolts_faceFSW" p15 "" "" ""))
      ((= ewc2 "coldformBSW-facing")(command "insert" "C:/lisps/8x4C_0.625abolts_faceBSW" p15 "" "" "")))
(setq bp10 (entlast))

(initget "Hotrolled coldformFSW-facing coldformBSW-facing")
(setq ewc3 (getkword "\nEW col#3 type: [Hotrolled/coldformFSW-facing/coldformBSW-facing]:"))
(cond ((= ewc3 "Hotrolled")(command "insert" "C:/lisps/w8x10_0.625abolts_lew" p7 "" "" ""))
      ((= ewc3 "coldformFSW-facing")(command "insert" "C:/lisps/8x4C_0.625abolts_faceFSW" "r" "180" p7 "" ""))
      ((= ewc3 "coldformBSW-facing")(command "insert" "C:/lisps/8x4C_0.625abolts_faceBSW" "r" "180" p7 "" "")))
(setq bp11 (entlast))

(initget "Hotrolled coldformFSW-facing coldformBSW-facing")
(setq ewc4 (getkword "\nEW col#4 type: [Hotrolled/coldformFSW-facing/coldformBSW-facing]:"))
(cond ((= ewc4 "Hotrolled")(command "insert" "C:/lisps/w8x10_0.625abolts_lew" p8 "" "" ""))
      ((= ewc4 "coldformFSW-facing")(command "insert" "C:/lisps/8x4C_0.625abolts_faceFSW" "r" "180" p8 "" ""))
      ((= ewc4 "coldformBSW-facing")(command "insert" "C:/lisps/8x4C_0.625abolts_faceBSW" "r" "180" p8 "" "")))
(setq bp11 (entlast))

(command "-LAYER" "S" "0" "")
)

image.png.7c6ad7ea8addadb7a49c90c753fd0956.png

Link to comment
Share on other sites

1 hour ago, devitg said:

@Sprunkle please upload a sample dwg , with text meaning each value from the textfile.txt

Forgive me as I flaunt my ignorance, but I am unsure of what you mean. I only started learning LISP about a week ago. But I am including the .dwg file that my code created, and I will include a text file that has the parameters that I typed in. If this is not what you meant, please let me know, and I will adjust. Thanks!

lisptest.dwg sample.txt

Link to comment
Share on other sites

@Sprunkle As neither english is my language,  and  construction  term . 

find attached what I did understood what you want to do.

Lisp usually get data from csv files,  so each line shall hold all data related .  

 

 

as to be.dwg

Link to comment
Share on other sites

(initget "Hotrolled coldformFSW-facing coldformBSW-facing")
(setq ewc4 (getkword "\nEW col#4 type: [Hotrolled/coldformFSW-facing/coldformBSW-facing]:"))

 

You can replace this with the multi radio buttons.lsp that I sent you.

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