error: stream is closed: #
Hello Everyone
I've been trying to get this code to work for me and when it gets to the (princ (strcat "SO" sta11 StaNumSp11 "0" inv22 InvNumSP22 "0" ) x), it seems to come up with the "error: stream is closed: # ". Its possible that there's another reason, but I just can't get it to work. (see attached code below)
Looked it up on Google but the solution offered to other people wasn't the same issue as mine. My intention is to rewrite the coordinates of the vertices and print them to a text file, with additional numbers and letters in the princ command.
I wouldn't say I'm new to programming, but I'm definitely still learning autolisp. I'd appreciate any input. Thank You
(defun C:GetVertex ()
(vl-load-com)
(setq sta1 (getreal "Enter Begining Station"))
(setq Inv1 (getreal "Enter Begining Elevation"))
(setq ent (car (entsel)))
(setq entl (entget ent))
(setq ct 0) ; set ct = 0
(setq file "C:/Users/mbec/Desktop/Temporary/Mytest.txt") ;
(setq x (open file "a"))
(repeat (length entl)
(if (= 10 (car (nth ct entl)))
(progn
(setq xcor (cadr (nth 14 entl)))
(setq ycor (caddr (nth 14 entl)))
; ALL program will take place below--------------------------
(if (= 14 ct)
(progn
(setq sta11 (rtos sta1 2 2))
(setq inv22 (rtos inv1 2 2))
(setq sta11L (strlen sta11))
(setq inv22L (strlen inv22))
(setq Station11FixLength 9)
(setq Invert22fixlength8 )
(setq numspaceSta11 (- station11fixlength sta11L))
(Setq numspaceInv22 (- invert22fixlength inv22L))
: spacing for Station-----------------------------------
(cond
( (= numspacesta11 2) (setq StaNumsp11(STRCAT "")))
( (= numspacesta11 3) (setq staNumSP11(STRCAT " ")))
( (= numspacesta11 4) (setq staNumSP11(STRCAT " ")))
( (= numspacesta11 5) (setq staNumSP11(STRCAT " ")))
( (= numspacesta11 6) (setq staNumSP11(STRCAT " ")))
)
: spacing for invert------------------------------------------
(cond
( (= numspaceinv22 1) (setq invNumsp22(STRCAT " ")))
( (= numspaceinv22 2) (setq invNumsp22(STRCAT "")))
( (= numspaceinv22 3) (setq InvNumSP22(STRCAT " ")))
( (= numspaceinv22 4) (setq InvNumSP22(STRCAT " ")))
( (= numspaceinv22 5) (setq InvNumSP22(STRCAT " ")))
( (= numspaceinv22 6) (setq InvNumSP22(STRCAT " ")))
)
(princ (strcat "SO" sta11 StaNumSp11 "0" inv22 InvNumSP22 "0" ) x)
)
; otherwise
(progn
(setq Element (getstring "Enter Element ID:"))
(if (= Element "R")
(prog
(setq x1 (rtos (+ (- (cadr (nth ct entl)) xcor) sta1 ) 2 2)) ; gets real number to the hundreds place
(setq y1 (rtos (+ (- (caddr (nth ct entl)) ycor) inv1) 2 2))
(Setq ChannelID(getreal "Enter ID Number for Channel:"))
(Setq Mannings(rtos (getreal "Enter Mannings N of Channel in following format .xxx:")2 3))
(Setq Radius(rtos (getreal "Enter Radius of Curve:") 2 2))
(Setq anglepoint(rtos (getreal "Enter Angle Point of Channel:") 2 2))
(Setq NumMH(getreal "Enter Number of Manholes:"))
(SETQ x1L(STRLEN X1))
(setq y1L(strlen y1))
(setq channelIDL (strlen channelid))
(setq manningsL(strlen mannings))
(setq radiusL( strlen radius))
(setq anglepointL(strlen anglepoint))
(setq numspaceSta (- 9 x1L)) ; 9 represents spaces available for Station input. ***REMEMBER TO DOULBE CHECK THAT ITS ACTUALLY 9
(Setq numspaceInv (- 8 y1L)) ; 8 represents spaces available for Station input. ***REMEMBER TO DOULBE CHECK THAT ITS ACTUALLY 9
(setq numspacechannelID (- 3 channelidL))
; none for mannings.
(setq numspaceRadius (- 8 radiusL))
(setq numspaceAnglePoint (- 8 anglepointL))
; spacing for Element---------------------------------------
(cond
( (= (- 4 (strlen Element)) 2) (setq Elementspa (strcat "")))
( (= (- 4 (strlen Element)) 3) (setq Elementspa (strcat " ")))
)
: spacing for Station-----------------------------------
(cond
( (= numspacesta 2) (setq NumspaceStaF(STRCAT "")))
( (= numspacesta 3) (setq NumspaceStaF(STRCAT " ")))
( (= numspacesta 4) (setq NumspaceStaF(STRCAT " ")))
( (= numspacesta 5) (setq NumspaceStaF(STRCAT " ")))
( (= numspacesta 6) (setq NumspaceStaF(STRCAT " ")))
)
: spacing for invert--------------
(cond
( (= numspaceinv 2) (setq numspaceInvF(STRCAT "")))
( (= numspaceinv 3) (setq numspaceInvF(STRCAT " ")))
( (= numspaceinv 4) (setq numspaceInvF(STRCAT " ")))
( (= numspaceinv 5) (setq numspaceInvF(STRCAT " ")))
( (= numspaceinv 6) (setq numspaceInvF(STRCAT " ")))
)
: spacing for channel id -----------------------------------
(cond
( (= numspacechannelid 2) (setq numspacechannelidf(STRCAT "")))
( (= numspacechannelid 3) (setq numspacechannelidf(STRCAT " ")))
( (= numspacechannelid 4) (setq numspacechannelidf(STRCAT " ")))
( (= numspacechannelid 5) (setq numspacechannelidf(STRCAT " ")))
( (= numspacechannelid 6) (setq numspacechannelidf(STRCAT " ")))
)
: spacing for radius(or curve angle) -----------------------------------
(cond
( (= numspaceradius 2) (setq numspaceradiusf(STRCAT "")))
( (= numspaceradius 3) (setq numspaceradiusf(STRCAT " ")))
( (= numspaceradius 4) (setq numspaceradiusf(STRCAT " ")))
( (= numspaceradius 5) (setq numspaceradiusf(STRCAT " ")))
( (= numspaceradius 6) (setq numspaceradiusf(STRCAT " ")))
)
: spacing for Angle Point -----------------------------------
(cond
( (= numspaceanglepoint 2) (setq numspaceanglepointf(STRCAT "")))
( (= numspaceanglepoint 3) (setq numspaceanglepointf(STRCAT " ")))
( (= numspaceanglepoint 4) (setq numspaceanglepointf(STRCAT " ")))
( (= numspaceanglepoint 5) (setq numspaceanglepointf(STRCAT " ")))
( (= numspaceanglepoint 6) (setq numspaceanglepointf(STRCAT " ")))
)
(princ (strcat "\n" Element Elementspa x1 numspacestaf "0" y1 numspaceinvf "0" numspacechannelidf channelid " " mannings " " numspaceradiusf radius numspaceanglepointf anglepoint NumMh) x) ; \n starts it in a new line.
); true of if (= Element "R")
); if of else of (if (= 14 ct))
); else of (if (= 14 ct))
); if (= 14 ct)
; else nothing
)
(setq ct (1+ ct))
)
(close x)
)
); idk where this goes...
Move the code below *outside* the repeat loop:
(close x)
And please read this:
http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines
Hello,
First you have to read this:
The code you posted looks kinda weird, so here are the corrections I did:
1. Formatted the code (for easier preview)
2. Localised all the variables read here about this
3. Fixed some typos, and comments (where was used ":" instead of ";")
4. Followed Roy's sharp eye
(defun C:GetVertex( / ; localise the variables: anglepoint anglepointl channelid channelidl ct element elementspa ent entl file inv1 inv22 inv22l invert22fixlength invnumsp22 mannings manningsl nummh numspaceanglepoint numspaceanglepointf numspacechannelid numspacechannelidf numspaceinv numspaceinv22 numspaceinvf numspaceradius numspaceradiusf numspacesta numspacesta11 numspacestaf radius radiusl sta1 sta11 sta11l stanumsp11 station11fixlength x x1 x1l xcor y1 y1l ycor)(if ; wrap with (if) function (and ; collect the inputs: if every statement within the (and) function is true, then continue (setq sta1 (getreal "Enter Begining Station")) (setq Inv1 (getreal "Enter Begining Elevation")) (setq ent (car (entsel "\nSelect object: "))) (or (setq file "C:/Users/mbec/Desktop/Temporary/Mytest.txt") ; (setq file (findfile "Mytest.txt")) (setq file (getfiled "Select the TXT File" "C:/Users/mbec/Desktop/Temporary/" "txt" 0)) ) ); and (progn ; evaluate the expresions wrapped in the (progn) function, if user filled the inputs (setq entl (entget ent)) (setq ct 0) ; set ct = 0 (setq x (open file "a")) (repeat (length entl) (if (= 10 (car (nth ct entl))) (progn (setq xcor (cadr (nth 14 entl))) (setq ycor (caddr (nth 14 entl))) ; ALL program will take place below-------------------------- (if (= 14 ct) (progn (setq sta11 (rtos sta1 2 2)) (setq inv22 (rtos inv1 2 2)) (setq sta11L (strlen sta11)) (setq inv22L (strlen inv22)) (setq Station11FixLength 9) (setq Invert22fixlength 8 ) (setq numspaceSta11 (- station11fixlength sta11L)) (setq numspaceInv22 (- invert22fixlength inv22L)) ; : spacing for Station----------------------------------- (cond ( (= numspacesta11 2) (setq StaNumsp11(STRCAT " "))) ( (= numspacesta11 3) (setq staNumSP11(STRCAT " "))) ( (= numspacesta11 4) (setq staNumSP11(STRCAT " "))) ( (= numspacesta11 5) (setq staNumSP11(STRCAT " "))) ( (= numspacesta11 6) (setq staNumSP11(STRCAT " "))) ) ; : spacing for invert------------------------------------------ (cond ( (= numspaceinv22 1) (setq invNumsp22(STRCAT " "))) ( (= numspaceinv22 2) (setq invNumsp22(STRCAT " "))) ( (= numspaceinv22 3) (setq InvNumSP22(STRCAT " "))) ( (= numspaceinv22 4) (setq InvNumSP22(STRCAT " "))) ( (= numspaceinv22 5) (setq InvNumSP22(STRCAT " "))) ( (= numspaceinv22 6) (setq InvNumSP22(STRCAT " "))) ) (princ (strcat "SO " sta11 StaNumSp11 "0" inv22 InvNumSP22 "0" ) x) ) ; otherwise (progn (setq Element (getstring "Enter Element ID:")) (if (= Element "R") (progn (setq x1 (rtos (+ (- (cadr (nth ct entl)) xcor) sta1 ) 2 2)) ; gets real number to the hundreds place (setq y1 (rtos (+ (- (caddr (nth ct entl)) ycor) inv1) 2 2)) (if (and (setq ChannelID (getreal "Enter ID Number for Channel:")) (setq Mannings (rtos (getreal "Enter Mannings N of Channel in following format .xxx:")2 3)) (setq Radius (rtos (getreal "Enter Radius of Curve:") 2 2)) (setq anglepoint (rtos (getreal "Enter Angle Point of Channel:") 2 2)) (setq NumMH (getreal "Enter Number of Manholes:")) ); and (progn (setq x1L (STRLEN X1)) (setq y1L (strlen y1)) (setq channelIDL (strlen channelid)) (setq manningsL(strlen mannings)) (setq radiusL( strlen radius)) (setq anglepointL(strlen anglepoint)) (setq numspaceSta (- 9 x1L)) ; 9 represents spaces available for Station input. ***REMEMBER TO DOULBE CHECK THAT ITS ACTUALLY 9 (setq numspaceInv (- 8 y1L)) ; 8 represents spaces available for Station input. ***REMEMBER TO DOULBE CHECK THAT ITS ACTUALLY 9 (setq numspacechannelID (- 3 channelidL)) ; none for mannings. (setq numspaceRadius (- 8 radiusL)) (setq numspaceAnglePoint (- 8 anglepointL)) ; spacing for Element--------------------------------------- (cond ( (= (- 4 (strlen Element)) 2) (setq Elementspa (strcat " "))) ( (= (- 4 (strlen Element)) 3) (setq Elementspa (strcat " "))) ) ; : spacing for Station----------------------------------- (cond ( (= numspacesta 2) (setq NumspaceStaF(STRCAT " "))) ( (= numspacesta 3) (setq NumspaceStaF(STRCAT " "))) ( (= numspacesta 4) (setq NumspaceStaF(STRCAT " "))) ( (= numspacesta 5) (setq NumspaceStaF(STRCAT " "))) ( (= numspacesta 6) (setq NumspaceStaF(STRCAT " "))) ) ; : spacing for invert-------------- (cond ( (= numspaceinv 2) (setq numspaceInvF(STRCAT " "))) ( (= numspaceinv 3) (setq numspaceInvF(STRCAT " "))) ( (= numspaceinv 4) (setq numspaceInvF(STRCAT " "))) ( (= numspaceinv 5) (setq numspaceInvF(STRCAT " "))) ( (= numspaceinv 6) (setq numspaceInvF(STRCAT " "))) ) ; : spacing for channel id ----------------------------------- (cond ( (= numspacechannelid 2) (setq numspacechannelidf(STRCAT " "))) ( (= numspacechannelid 3) (setq numspacechannelidf(STRCAT " "))) ( (= numspacechannelid 4) (setq numspacechannelidf(STRCAT " "))) ( (= numspacechannelid 5) (setq numspacechannelidf(STRCAT " "))) ( (= numspacechannelid 6) (setq numspacechannelidf(STRCAT " "))) ) ; : spacing for radius(or curve angle) ----------------------------------- (cond ( (= numspaceradius 2) (setq numspaceradiusf(STRCAT " "))) ( (= numspaceradius 3) (setq numspaceradiusf(STRCAT " "))) ( (= numspaceradius 4) (setq numspaceradiusf(STRCAT " "))) ( (= numspaceradius 5) (setq numspaceradiusf(STRCAT " "))) ( (= numspaceradius 6) (setq numspaceradiusf(STRCAT " "))) ) ; : spacing for Angle Point ----------------------------------- (cond ( (= numspaceanglepoint 2) (setq numspaceanglepointf(STRCAT " "))) ( (= numspaceanglepoint 3) (setq numspaceanglepointf(STRCAT " "))) ( (= numspaceanglepoint 4) (setq numspaceanglepointf(STRCAT " "))) ( (= numspaceanglepoint 5) (setq numspaceanglepointf(STRCAT " "))) ( (= numspaceanglepoint 6) (setq numspaceanglepointf(STRCAT " "))) ) (princ (strcat "\n" ; \n starts it in a new line. Element Elementspa x1 numspacestaf "0" y1 numspaceinvf "0" numspacechannelidf channelid " " mannings " " numspaceradiusf radius numspaceanglepointf anglepoint NumMh ); strcat ); princ ); progn ); if ); progn ; true of if (= Element "R") ); if of else of (if (= 14 ct)) ); else of (if (= 14 ct)) ); if (= 14 ct) ; else nothing ); progn (setq ct (1+ ct)) ); if ); repeat (and x (close x)) ); progn); if inputs(princ) ; exit cleanly); defun(vl-load-com) ; load the visual lisp extensions, its used once only
Thank you Roy_043. I'll give this a shot and see if I run into any other problems.
I appreciate your input and I'll definitely take some time to read the link.
hi @mbecerra24,
(cond ((= numspacesta11 2) (setq StaNumsp11 (STRCAT " "))) ((= numspacesta11 3) (setq staNumSP11 (STRCAT " "))) ((= numspacesta11 4) (setq staNumSP11 (STRCAT " "))) ((= numspacesta11 5) (setq staNumSP11 (STRCAT " "))) ((= numspacesta11 6) (setq staNumSP11 (STRCAT " "))) )
which means if in any condition numspacesta11= 2,3,4,5,6, it will be the same result:
(setq staNumSP11 (STRCAT " "))
IMO or ,vl-some better than cond in this case
p/s: sorry off topic
This reminds me in very old thread Roy advised & pointed out my code used too many repeating "if", which he proposed using "and", then i improved my mistake. thanks @Roy
Good catch, you forgot to include also vl-position and member
@OP HTH too
Could use an if also > 1.9999 and
页:
[1]
I've been trying to get this code to work for me and when it gets to the (princ (strcat "SO" sta11 StaNumSp11 "0" inv22 InvNumSP22 "0" ) x), it seems to come up with the "error: stream is closed: # ". Its possible that there's another reason, but I just can't get it to work. (see attached code below)
Looked it up on Google but the solution offered to other people wasn't the same issue as mine. My intention is to rewrite the coordinates of the vertices and print them to a text file, with additional numbers and letters in the princ command.
I wouldn't say I'm new to programming, but I'm definitely still learning autolisp. I'd appreciate any input. Thank You
(defun C:GetVertex ()
(vl-load-com)
(setq sta1 (getreal "Enter Begining Station"))
(setq Inv1 (getreal "Enter Begining Elevation"))
(setq ent (car (entsel)))
(setq entl (entget ent))
(setq ct 0) ; set ct = 0
(setq file "C:/Users/mbec/Desktop/Temporary/Mytest.txt") ;
(setq x (open file "a"))
(repeat (length entl)
(if (= 10 (car (nth ct entl)))
(progn
(setq xcor (cadr (nth 14 entl)))
(setq ycor (caddr (nth 14 entl)))
; ALL program will take place below--------------------------
(if (= 14 ct)
(progn
(setq sta11 (rtos sta1 2 2))
(setq inv22 (rtos inv1 2 2))
(setq sta11L (strlen sta11))
(setq inv22L (strlen inv22))
(setq Station11FixLength 9)
(setq Invert22fixlength8 )
(setq numspaceSta11 (- station11fixlength sta11L))
(Setq numspaceInv22 (- invert22fixlength inv22L))
: spacing for Station-----------------------------------
(cond
( (= numspacesta11 2) (setq StaNumsp11(STRCAT "")))
( (= numspacesta11 3) (setq staNumSP11(STRCAT " ")))
( (= numspacesta11 4) (setq staNumSP11(STRCAT " ")))
( (= numspacesta11 5) (setq staNumSP11(STRCAT " ")))
( (= numspacesta11 6) (setq staNumSP11(STRCAT " ")))
)
: spacing for invert------------------------------------------
(cond
( (= numspaceinv22 1) (setq invNumsp22(STRCAT " ")))
( (= numspaceinv22 2) (setq invNumsp22(STRCAT "")))
( (= numspaceinv22 3) (setq InvNumSP22(STRCAT " ")))
( (= numspaceinv22 4) (setq InvNumSP22(STRCAT " ")))
( (= numspaceinv22 5) (setq InvNumSP22(STRCAT " ")))
( (= numspaceinv22 6) (setq InvNumSP22(STRCAT " ")))
)
(princ (strcat "SO" sta11 StaNumSp11 "0" inv22 InvNumSP22 "0" ) x)
)
; otherwise
(progn
(setq Element (getstring "Enter Element ID:"))
(if (= Element "R")
(prog
(setq x1 (rtos (+ (- (cadr (nth ct entl)) xcor) sta1 ) 2 2)) ; gets real number to the hundreds place
(setq y1 (rtos (+ (- (caddr (nth ct entl)) ycor) inv1) 2 2))
(Setq ChannelID(getreal "Enter ID Number for Channel:"))
(Setq Mannings(rtos (getreal "Enter Mannings N of Channel in following format .xxx:")2 3))
(Setq Radius(rtos (getreal "Enter Radius of Curve:") 2 2))
(Setq anglepoint(rtos (getreal "Enter Angle Point of Channel:") 2 2))
(Setq NumMH(getreal "Enter Number of Manholes:"))
(SETQ x1L(STRLEN X1))
(setq y1L(strlen y1))
(setq channelIDL (strlen channelid))
(setq manningsL(strlen mannings))
(setq radiusL( strlen radius))
(setq anglepointL(strlen anglepoint))
(setq numspaceSta (- 9 x1L)) ; 9 represents spaces available for Station input. ***REMEMBER TO DOULBE CHECK THAT ITS ACTUALLY 9
(Setq numspaceInv (- 8 y1L)) ; 8 represents spaces available for Station input. ***REMEMBER TO DOULBE CHECK THAT ITS ACTUALLY 9
(setq numspacechannelID (- 3 channelidL))
; none for mannings.
(setq numspaceRadius (- 8 radiusL))
(setq numspaceAnglePoint (- 8 anglepointL))
; spacing for Element---------------------------------------
(cond
( (= (- 4 (strlen Element)) 2) (setq Elementspa (strcat "")))
( (= (- 4 (strlen Element)) 3) (setq Elementspa (strcat " ")))
)
: spacing for Station-----------------------------------
(cond
( (= numspacesta 2) (setq NumspaceStaF(STRCAT "")))
( (= numspacesta 3) (setq NumspaceStaF(STRCAT " ")))
( (= numspacesta 4) (setq NumspaceStaF(STRCAT " ")))
( (= numspacesta 5) (setq NumspaceStaF(STRCAT " ")))
( (= numspacesta 6) (setq NumspaceStaF(STRCAT " ")))
)
: spacing for invert--------------
(cond
( (= numspaceinv 2) (setq numspaceInvF(STRCAT "")))
( (= numspaceinv 3) (setq numspaceInvF(STRCAT " ")))
( (= numspaceinv 4) (setq numspaceInvF(STRCAT " ")))
( (= numspaceinv 5) (setq numspaceInvF(STRCAT " ")))
( (= numspaceinv 6) (setq numspaceInvF(STRCAT " ")))
)
: spacing for channel id -----------------------------------
(cond
( (= numspacechannelid 2) (setq numspacechannelidf(STRCAT "")))
( (= numspacechannelid 3) (setq numspacechannelidf(STRCAT " ")))
( (= numspacechannelid 4) (setq numspacechannelidf(STRCAT " ")))
( (= numspacechannelid 5) (setq numspacechannelidf(STRCAT " ")))
( (= numspacechannelid 6) (setq numspacechannelidf(STRCAT " ")))
)
: spacing for radius(or curve angle) -----------------------------------
(cond
( (= numspaceradius 2) (setq numspaceradiusf(STRCAT "")))
( (= numspaceradius 3) (setq numspaceradiusf(STRCAT " ")))
( (= numspaceradius 4) (setq numspaceradiusf(STRCAT " ")))
( (= numspaceradius 5) (setq numspaceradiusf(STRCAT " ")))
( (= numspaceradius 6) (setq numspaceradiusf(STRCAT " ")))
)
: spacing for Angle Point -----------------------------------
(cond
( (= numspaceanglepoint 2) (setq numspaceanglepointf(STRCAT "")))
( (= numspaceanglepoint 3) (setq numspaceanglepointf(STRCAT " ")))
( (= numspaceanglepoint 4) (setq numspaceanglepointf(STRCAT " ")))
( (= numspaceanglepoint 5) (setq numspaceanglepointf(STRCAT " ")))
( (= numspaceanglepoint 6) (setq numspaceanglepointf(STRCAT " ")))
)
(princ (strcat "\n" Element Elementspa x1 numspacestaf "0" y1 numspaceinvf "0" numspacechannelidf channelid " " mannings " " numspaceradiusf radius numspaceanglepointf anglepoint NumMh) x) ; \n starts it in a new line.
); true of if (= Element "R")
); if of else of (if (= 14 ct))
); else of (if (= 14 ct))
); if (= 14 ct)
; else nothing
)
(setq ct (1+ ct))
)
(close x)
)
); idk where this goes... Move the code below *outside* the repeat loop:
(close x)
And please read this:
http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines Hello,
First you have to read this:
The code you posted looks kinda weird, so here are the corrections I did:
1. Formatted the code (for easier preview)
2. Localised all the variables read here about this
3. Fixed some typos, and comments (where was used ":" instead of ";")
4. Followed Roy's sharp eye
(defun C:GetVertex( / ; localise the variables: anglepoint anglepointl channelid channelidl ct element elementspa ent entl file inv1 inv22 inv22l invert22fixlength invnumsp22 mannings manningsl nummh numspaceanglepoint numspaceanglepointf numspacechannelid numspacechannelidf numspaceinv numspaceinv22 numspaceinvf numspaceradius numspaceradiusf numspacesta numspacesta11 numspacestaf radius radiusl sta1 sta11 sta11l stanumsp11 station11fixlength x x1 x1l xcor y1 y1l ycor)(if ; wrap with (if) function (and ; collect the inputs: if every statement within the (and) function is true, then continue (setq sta1 (getreal "Enter Begining Station")) (setq Inv1 (getreal "Enter Begining Elevation")) (setq ent (car (entsel "\nSelect object: "))) (or (setq file "C:/Users/mbec/Desktop/Temporary/Mytest.txt") ; (setq file (findfile "Mytest.txt")) (setq file (getfiled "Select the TXT File" "C:/Users/mbec/Desktop/Temporary/" "txt" 0)) ) ); and (progn ; evaluate the expresions wrapped in the (progn) function, if user filled the inputs (setq entl (entget ent)) (setq ct 0) ; set ct = 0 (setq x (open file "a")) (repeat (length entl) (if (= 10 (car (nth ct entl))) (progn (setq xcor (cadr (nth 14 entl))) (setq ycor (caddr (nth 14 entl))) ; ALL program will take place below-------------------------- (if (= 14 ct) (progn (setq sta11 (rtos sta1 2 2)) (setq inv22 (rtos inv1 2 2)) (setq sta11L (strlen sta11)) (setq inv22L (strlen inv22)) (setq Station11FixLength 9) (setq Invert22fixlength 8 ) (setq numspaceSta11 (- station11fixlength sta11L)) (setq numspaceInv22 (- invert22fixlength inv22L)) ; : spacing for Station----------------------------------- (cond ( (= numspacesta11 2) (setq StaNumsp11(STRCAT " "))) ( (= numspacesta11 3) (setq staNumSP11(STRCAT " "))) ( (= numspacesta11 4) (setq staNumSP11(STRCAT " "))) ( (= numspacesta11 5) (setq staNumSP11(STRCAT " "))) ( (= numspacesta11 6) (setq staNumSP11(STRCAT " "))) ) ; : spacing for invert------------------------------------------ (cond ( (= numspaceinv22 1) (setq invNumsp22(STRCAT " "))) ( (= numspaceinv22 2) (setq invNumsp22(STRCAT " "))) ( (= numspaceinv22 3) (setq InvNumSP22(STRCAT " "))) ( (= numspaceinv22 4) (setq InvNumSP22(STRCAT " "))) ( (= numspaceinv22 5) (setq InvNumSP22(STRCAT " "))) ( (= numspaceinv22 6) (setq InvNumSP22(STRCAT " "))) ) (princ (strcat "SO " sta11 StaNumSp11 "0" inv22 InvNumSP22 "0" ) x) ) ; otherwise (progn (setq Element (getstring "Enter Element ID:")) (if (= Element "R") (progn (setq x1 (rtos (+ (- (cadr (nth ct entl)) xcor) sta1 ) 2 2)) ; gets real number to the hundreds place (setq y1 (rtos (+ (- (caddr (nth ct entl)) ycor) inv1) 2 2)) (if (and (setq ChannelID (getreal "Enter ID Number for Channel:")) (setq Mannings (rtos (getreal "Enter Mannings N of Channel in following format .xxx:")2 3)) (setq Radius (rtos (getreal "Enter Radius of Curve:") 2 2)) (setq anglepoint (rtos (getreal "Enter Angle Point of Channel:") 2 2)) (setq NumMH (getreal "Enter Number of Manholes:")) ); and (progn (setq x1L (STRLEN X1)) (setq y1L (strlen y1)) (setq channelIDL (strlen channelid)) (setq manningsL(strlen mannings)) (setq radiusL( strlen radius)) (setq anglepointL(strlen anglepoint)) (setq numspaceSta (- 9 x1L)) ; 9 represents spaces available for Station input. ***REMEMBER TO DOULBE CHECK THAT ITS ACTUALLY 9 (setq numspaceInv (- 8 y1L)) ; 8 represents spaces available for Station input. ***REMEMBER TO DOULBE CHECK THAT ITS ACTUALLY 9 (setq numspacechannelID (- 3 channelidL)) ; none for mannings. (setq numspaceRadius (- 8 radiusL)) (setq numspaceAnglePoint (- 8 anglepointL)) ; spacing for Element--------------------------------------- (cond ( (= (- 4 (strlen Element)) 2) (setq Elementspa (strcat " "))) ( (= (- 4 (strlen Element)) 3) (setq Elementspa (strcat " "))) ) ; : spacing for Station----------------------------------- (cond ( (= numspacesta 2) (setq NumspaceStaF(STRCAT " "))) ( (= numspacesta 3) (setq NumspaceStaF(STRCAT " "))) ( (= numspacesta 4) (setq NumspaceStaF(STRCAT " "))) ( (= numspacesta 5) (setq NumspaceStaF(STRCAT " "))) ( (= numspacesta 6) (setq NumspaceStaF(STRCAT " "))) ) ; : spacing for invert-------------- (cond ( (= numspaceinv 2) (setq numspaceInvF(STRCAT " "))) ( (= numspaceinv 3) (setq numspaceInvF(STRCAT " "))) ( (= numspaceinv 4) (setq numspaceInvF(STRCAT " "))) ( (= numspaceinv 5) (setq numspaceInvF(STRCAT " "))) ( (= numspaceinv 6) (setq numspaceInvF(STRCAT " "))) ) ; : spacing for channel id ----------------------------------- (cond ( (= numspacechannelid 2) (setq numspacechannelidf(STRCAT " "))) ( (= numspacechannelid 3) (setq numspacechannelidf(STRCAT " "))) ( (= numspacechannelid 4) (setq numspacechannelidf(STRCAT " "))) ( (= numspacechannelid 5) (setq numspacechannelidf(STRCAT " "))) ( (= numspacechannelid 6) (setq numspacechannelidf(STRCAT " "))) ) ; : spacing for radius(or curve angle) ----------------------------------- (cond ( (= numspaceradius 2) (setq numspaceradiusf(STRCAT " "))) ( (= numspaceradius 3) (setq numspaceradiusf(STRCAT " "))) ( (= numspaceradius 4) (setq numspaceradiusf(STRCAT " "))) ( (= numspaceradius 5) (setq numspaceradiusf(STRCAT " "))) ( (= numspaceradius 6) (setq numspaceradiusf(STRCAT " "))) ) ; : spacing for Angle Point ----------------------------------- (cond ( (= numspaceanglepoint 2) (setq numspaceanglepointf(STRCAT " "))) ( (= numspaceanglepoint 3) (setq numspaceanglepointf(STRCAT " "))) ( (= numspaceanglepoint 4) (setq numspaceanglepointf(STRCAT " "))) ( (= numspaceanglepoint 5) (setq numspaceanglepointf(STRCAT " "))) ( (= numspaceanglepoint 6) (setq numspaceanglepointf(STRCAT " "))) ) (princ (strcat "\n" ; \n starts it in a new line. Element Elementspa x1 numspacestaf "0" y1 numspaceinvf "0" numspacechannelidf channelid " " mannings " " numspaceradiusf radius numspaceanglepointf anglepoint NumMh ); strcat ); princ ); progn ); if ); progn ; true of if (= Element "R") ); if of else of (if (= 14 ct)) ); else of (if (= 14 ct)) ); if (= 14 ct) ; else nothing ); progn (setq ct (1+ ct)) ); if ); repeat (and x (close x)) ); progn); if inputs(princ) ; exit cleanly); defun(vl-load-com) ; load the visual lisp extensions, its used once only Thank you Roy_043. I'll give this a shot and see if I run into any other problems.
I appreciate your input and I'll definitely take some time to read the link. hi @mbecerra24,
(cond ((= numspacesta11 2) (setq StaNumsp11 (STRCAT " "))) ((= numspacesta11 3) (setq staNumSP11 (STRCAT " "))) ((= numspacesta11 4) (setq staNumSP11 (STRCAT " "))) ((= numspacesta11 5) (setq staNumSP11 (STRCAT " "))) ((= numspacesta11 6) (setq staNumSP11 (STRCAT " "))) )
which means if in any condition numspacesta11= 2,3,4,5,6, it will be the same result:
(setq staNumSP11 (STRCAT " "))
IMO or ,vl-some better than cond in this case
p/s: sorry off topic
This reminds me in very old thread Roy advised & pointed out my code used too many repeating "if", which he proposed using "and", then i improved my mistake. thanks @Roy Good catch, you forgot to include also vl-position and member @OP HTH too Could use an if also > 1.9999 and
页:
[1]