×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Input data from .txt file

Input data from .txt file

Input data from .txt file

(OP)
I wrote a lisp program for draw profile.
But I have trouble with input data from text file , ex : I input data in Excel file after that save as to text file.
In data have two colunme
Elev Distance
2.0  100
1.0  300
I need a advice for write this sub-code.
Hope someone help me.
Thanks you very much.
 

 



RE: Input data from .txt file

Hi, cad123:

I can give you a hand if you send me a copy of your file.

Roberttx.

RE: Input data from .txt file

(OP)
This is source code I took from net and modified it to fit with my work.
I done with manual input.
Thanks
;;;;;;;;;;;;;;;;;;;;;;;;
;lisp file, file name QpB.lsp command qpb
(defun prof (/ cm p1 p2 dist1 dist2 d1 d2 d3 d4 in1 in2 in it1 it2 it do)
(if (tblsearch "layer" "C-SSWR1")
       (command  "-layer" "S" "C-SSWR1" "")
       (command  "-layer" "N" "C-SSWR1" "c" 3 "C-SSWR1" "L" "Continuous" "C-SSWR1" "s" "C-SSWR1" "")
       )
  (setq cm (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq vs (atof vs))
  (setq hs (atof hs))
  (setvar "osmode"  512)
  (setq p2 (getpoint "\nElevation 0.0: "))
  (print p2)
  (if (= p2 nil)(quit))
  (setvar "osmode"  0)
  (setq d1 (getreal "\Provide start Elevation: "))
  ;(if (= d1 "")(quit))
  (setq d2 (* vs d1))
  ;(print d2)
  (setq d3 (cadr p2) )
  ;(type d3)
  ;(print d3)    
  (setq d4 (- d3 d2))
  ;(print d4)    
 ; (setq d5 (rtos d4 2 3))
  ;(print d5)
 ; (setq k (- (cadr p2) d) )
  (setq p1 (list(car p2) (+ d3 d2)))
  ;(print p1)
   (setq dist (getreal "\Provide Horiz. Distance: "))
  (if (= dist "")(quit))
  (setq dist2 (* hs dist))
  (setq dist1 (rtos dist2))
  (setq it (getreal "\nProvide Elevation: "))
  (if (= it "")(quit))
  (setq it2 (-(* vs it)d2))
  (setq it1 (rtos it2))
  (setq do (strcat "@" dist1 "," it1))
  ;(print do)
    

  (command "pline" p1 do "")
  (command"pedit" "l" "" "")
  (command "select" "l" "")
  (setq d5 (* vs it))
(while
    (setq dist (getreal "\Provide Horiz. Distance or press return when done: "))
    (if (= dist "")(quit))
    (setq dist2 (* hs dist))
    (setq dist1 (rtos dist2))
    (setq in (getreal "\nProvide Elevation: "))
    (if (= in "")(quit))
    (setq in2 (-(* vs in) d5 ))
    (setq in1 (rtos in2))
    (setq do (strcat "@" dist1 "," in1))
    (setq do (strcat "@" dist1 "," in1))
    (command "pline" "" do "")
    (command"pedit" "l" "" "")
    (command "pedit" "l" "j" "p" "" "")
    (command "select" "l" "")
    (setq d5 (* vs in))
  )
(setvar"cmdecho" cm)
(princ)
)
;===============================================================
(defun eb1 ()
(setq vs (get_tile "eb1"))
)
;===============================================================
(defun eb2 ()
(setq hs (get_tile "eb2"))
)
;===============================================================
(defun rb1 ();(/ man)
(setq man (get_tile "rb1"))
)
;===============================================================
(defun rb2 ();(/ fil)
(setq fil (get_tile "rb2"))
)
;===============================================================
(defun hlp()
(help"qpb")
)
;===========================================================;===========================================================(defun c:qpb (/ eb1a eb2a)
    (setq vs nil)
    (setq hs nil)
     (setq man nil)
     (setq fil nil)
   (setq dcl_id (load_dialog "qpb.dcl"))
   (if (not (new_dialog "qpb" dcl_id)) (exit))
   
   (setq rrb1 "1")
   (set_tile "rb1" rrb1)
   (mode_tile "rb1" 2)
 
   (setq eb1a "1")
   (set_tile "eb1" eb1a)
   (mode_tile "eb1" 2)
   
   (setq eb2a "1")
   (set_tile "eb2" eb2a)
   (mode_tile "eb2" 2)  

   (action_tile "eb1" "(eb1)")
   (action_tile "eb2" "(eb2)")
 
   (action_tile "rb1" "(rb1)")
   (action_tile "rb2" "(rb2)")
;
   (action_tile "accept" "(done_dialog)")
   (action_tile "cancel" "(exit)")
   (action_tile "help" "(hlp)")
   ;
   (start_dialog)
   (unload_dialog dcl_id)
;=======================================================
  (if (= vs nil)(setq vs "1"))
  (if (= hs nil)(setq hs "1"))
  (if
    (and
     (= man nil)
     (= fil nil)
    )
    (setq man "1")
  )
  (cond
    ((= man "1")(prof))
    ((= fil "1")(alert"\nComming Soon...I am working on it!"))
   )  

   (princ)
)
 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;dcl file, file name QpB.dcl

dcl_settings : default_dcl_settings { audit_level = 3 ; }
qpb : dialog {
    initial_focus = "rb1" ;
    key = "qpb" ;
    label = "qpb" ;
    value = "Quick Profile Builder" ;
    : row {
        key = "r1" ;
        : edit_box {
            fixed_width = true ;
            key = "eb1" ;
            label = "Vertical Scale:" ;
            width = 10 ;
        }
        : spacer {
            fixed_width = true ;
            width = 4 ;
        }
        : edit_box {
            fixed_width = true ;
            key = "eb2" ;
            label = "Horizontal Scale:" ;
            width = 10 ;
        }
    }
    : radio_row {
        key = "rr1" ;
        : radio_button {
            key = "rb1" ;
            label = "Manual" ;
            width = 2 ;
        }
        : radio_button {
            key = "rb2" ;
            label = "From File" ;
            width = 2 ;
        }
        : spacer {
            fixed_width = true ;
            width = 22 ;
        }
    }
    ok_cancel_help ;
}

RE: Input data from .txt file

If you are drawing a profile, it may be easier to just put the data in excel. Create a column that combines the x & y into a format of "x,y". This can be done with the concatenate command or a line similar to =A1&","&B1.  Copy-clip the column. Inside of Acad start the Pline command, pull up the text window (F2), under Edit hit Paste. The profile will draw itself.

Also with this procedure, you can control the scaling of the x or y within excel before pasting.

RE: Input data from .txt file

Hi, Bayou:

Nobody could say it better. I guess that's the simplest solution to create a profile with such data.
Roberttx.

RE: Input data from .txt file

(OP)
Hi Bayou,
Your method is Ok. but it does not look like professional way.
Roberttx : how is your comment about lisp file ? Too mess ;)

RE: Input data from .txt file

Hi, cad123:

I read it. I am not into dialog boxes. I am sorry. Good luck. Anyway, using Bayou's suggestion, you can still modify the profile using custom made lisp apps, like labeling slope, endpoints, lengths, etc. For instance, I am sending you a slope program I made.

Robertx.

(defun c:sc5 ()
(setvar "cmdecho" 0)
(setq old_osnap (getvar "osmode"))
(setvar "osmode" 512)
(princ "\nSlope on x-section grid.")
(setq
p1 (getpoint "\nFrom point.")
p2 (getpoint "...to point...")
dify (- (cadr p2) (cadr p1))
difx (- (car p2)  (car p1))
sl5 (/
(* dify 5.0)
(* difx 10.0)
)
invslope (/ 1.0 sl5)
sl5 (rtos sl5 2 3)
invslope (strcat (rtos invslope 2 2) ":1")
)
(princ "\nSlope= ")(princ sl5)(princ " or ")(princ invslope)
(setvar "osmode" old_osnap)
(princ)
);defun

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources