乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 42|回复: 7

[编程交流] error: stream is closed: #

[复制链接]

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 16:52:17 | 显示全部楼层 |阅读模式
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 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")
       (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...
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 17:02:28 | 显示全部楼层
Move the code below *outside* the repeat loop:
  1. (close x)
 
And please read this:
http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 17:14:41 | 显示全部楼层
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
  1. (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
回复

使用道具 举报

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 17:18:13 | 显示全部楼层
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.
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 17:30:43 | 显示全部楼层
hi @mbecerra24,
 
  1. (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
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 17:42:20 | 显示全部楼层
Good catch, you forgot to include also vl-position and member
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 17:43:53 | 显示全部楼层
@OP HTH too
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 17:58:05 | 显示全部楼层
Could use an if also > 1.9999 and
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 13:02 , Processed in 0.424646 second(s), 68 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表