如何使用导出坐标数据
大家好,请容忍我,因为我是Autolisp的相对新手,我已经在互联网上筛选了一个多星期了,试图找到一个Lisp例程,使我能够在图形上拾取点,并在屏幕上自动标记它们的东距和北距。
我最终做到了这一点,主要是通过剖析互联网上的其他Lisp例程,并阅读当地图书馆的几本(可能已经过时)书籍。我不确定在修改其他人的例程时是否正确,所以如果我做错了什么,请告诉我。
无论如何,下面是到目前为止的Lsip例程,但我一辈子都不知道如何将每组坐标导出到ASCII文件,以便上传到全站仪。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; IDXYZ.LSP ;
; This routine is based on: ;
; TIP #940:IDXYZ.LSP (C)1994, JOHN R. RICKER ;
; Taken from a post on the AUGI website ;
; ;
; Example Run : ;
; Enter Desired Text Size ? : ;
; UNIT type to use cientific ec rchitect ng ract : ;
; Enter number of Decimal Places to use ? < 3 > : ;
; Please pick POINT to ID and label with TEXT... <do so> ;
; ************* continues until carriage return is hit *************** ;
; Please pick POINT to ID and label with TEXT... <do so> ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(princ "\Loading IDXY Please Wait..")
(setvar "CMDECHO" 0)
(setq OS (getvar "OSMODE"))
(setq currlay (getvar "clayer"))
(setq txtstyl (getvar "textstyle"))
(command "style" "UTM" "romans" "0" "1" "0" "N" "N" "N")
(command "Layer" "M" "UTM-Text" "S" "UTM-Text" "")
;set trailing zeros to on
;
(initget 1 "S H")
(setq DMZ
(getkword
"\nTrailing Zeros how or ide : "))
(cond ((= DMZ "S")(setq DMZ 3))
((= DMZ "H")(setq DMZ )
) ; end cond
(setvar "DIMZIN" DMZ)
;
; get the text size to use
;
(setq TXTSZ
(getreal "\n Enter Desired Text Size ? : "))
;
; get the unit type to display
;
(initget 1 "S D E A F")
(setq UT
(getkword
"\nUNIT type to use cientific ec rchitect ng ract : "))
(cond ((= UT "S")(setq UT 1))
((= UT "D")(setq UT 2))
((= UT "E")(setq UT 3))
((= UT "A")(setq UT 4))
((= UT "F")(setq UT 5))
) ; end cond
;
; get the number of decimal places to use
;
(setq DP
(getint "\n Enter number of Decimal Places to use ? < 3 > : "))
(if (or (= DP "")(= DP nil))(setq DP 3))
;
; get insertion point first time in...
;
(setq PT
(getpoint "\n Please pick POINT to ID and label with TEXT... (hit Enter when done) "))
(while PT
(setq VAL1$ (strcat (rtos (car PT) UT DP) "mE"))
(setq VAL2$ (strcat (rtos (cadr PT) UT DP) "mN"))
(command "TEXT" (polar PT 0 TXTSZ) TXTSZ "0" VAL1$ "text" "" VAL2$)
; (command "TEXT" PT "" VAL1$ "text" "" VAL2$))
;
;
; get insertion point while in loop
(setq PT
(getpoint "\n Please pick POINT to ID and label with TEXT... (hit Enter when done) "))
) ; end while
;
; reset OSMODE
;
(setvar "OSMODE" OS)
(setvar "clayer" currlay)
(setvar "textstyle" txtstyl)
(terpri)
) ; end defun
(princ "IDXY Loaded.... Command = IDXY \n")
(princ)
; end idxy.lsp
任何帮助都将不胜感激。
干杯 我看到没有比他更有能力的人回应了,所以我来了。要将字符串保存在ascii文件中,首先需要使用以下内容声明文件变量:
(setq fvar(打开“gpoints.txt”“w”))
这可能就在这条线之后:
; 首次在中获取插入点。。。
然后,要编写字符串,需要如下内容:
(写入行VAL1$fvar)
(写入行VAL2$fvar)
该对需要出现在定义字符串之后、getpoint语句之前的while循环中。那么就在排队之前呢:
; 在循环中获取插入点
然后,在while循环关闭后,您需要使用以下命令关闭文件:
(关闭fvar)
这方面的一个好地方可能是在台词后面:;重置OSMODE
我希望这能奏效。你发布的代码似乎不完整,至少我找不到开头的DEFUN,所以我无法自己运行和测试它。
我也不知道gpoints在哪里。我的示例中的txt文件实际上位于您的系统上。您可能需要为其定义一个文件夹。
关于版权问题,我不是律师,但我想作者不会在乎你如何使用代码,除非你打算出售一个包含他的代码的程序。然后你应该联系他并请求许可。
祝你好运。 看一看这个,看5分
笔记剪切另一个程序未完成
(repeat 5
(setq el (entget))
(setq ip (cdr (assoc 10 el)))
(setq en1 (entnext en))
(setq el1 (entget en1))
(setq att (cdr (assoc 1 el1)))
(setq px (rtos (car ip) 2 3))
(setq py (rtos (cadr ip) 2 3))
(setq pz (rtos (caddr ip) 2 3))
(setq pnt (strcat att "," px ", " py ", " pz))
(write-line pnt filename)
)
干杯,这似乎起了作用,我已经添加了defun,并把事情整理了一点。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; IDXYZ.LSP ;
; This routine is based on: ;
; TIP #940:IDXYZ.LSP (C)1994, JOHN R. RICKER ;
; Taken from a post on the AUGI website ;
; ;
; Example Run : ;
; Trailing Zeros how or ide ? ;
; Enter Desired Text Size ? : ;
; UNIT type to use cientific ec rchitect ng ract : ;
; Enter number of Decimal Places to use ? < 3 > : ;
; Please pick POINT to ID and label with TEXT... <do so> ;
; ************* continues until carriage return is hit *************** ;
; Please pick POINT to ID and label with TEXT... <do so> ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(princ "\Loading IDXY Please Wait..")
(defun C:IDXY ( / TYP OS ANS XYZ$ DP DMZ UT currlay txtstyl)
(setvar "CMDECHO" 0)
(setq OS (getvar "OSMODE"))
(setq currlay (getvar "clayer"))
(setq txtstyl (getvar "textstyle"))
(command "style" "UTM" "romans" "0" "1" "0" "N" "N" "N")
(command "Layer" "M" "UTM-Text" "S" "UTM-Text" "")
;
; set trailing zeros to on or off
;
(initget 1 "S H")
(setq DMZ
(getkword "\nTrailing Zeros how or ide ? : "))
(cond ((= DMZ "S")(setq DMZ 3))
((= DMZ "H")(setq DMZ )
) ; end cond
(setvar "DIMZIN" DMZ)
;
; set the text size to use
;
(setq TXTSZ
(getreal "\n Enter Desired Text Size ? : "))
;
; set the unit type to display
;
(initget 1 "S D E A F")
(setq UT
(getkword
"\nUNIT type to use cientific ec rchitect ng ract : "))
(cond ((= UT "S")(setq UT 1))
((= UT "D")(setq UT 2))
((= UT "E")(setq UT 3))
((= UT "A")(setq UT 4))
((= UT "F")(setq UT 5))
) ; end cond
;
; set the number of decimal places to use
;
(setq DP
(getint "\n Enter number of Decimal Places to use ? < 3 > : "))
(if (or (= DP "")(= DP nil))(setq DP 3))
;
;
; get insertion point first time in...
;
; open file for writing using drawing location and drawing name
;
(setq fname (strcase (strcat (getvar "dwgprefix") (getvar "dwgname") ".xyz")))
(setq fvar (open fname "a"))
;
; pick 1st point
;
(setq PT
(getpoint "\n Please pick POINT to ID and label with TEXT... (hit Enter when done) "))
(while PT
;
; variable for on screen display (inc mE & mN)
;
(setq VAL1$ (strcat (rtos (car PT) UT DP)"mE"))
(setq VAL2$ (strcat (rtos (cadr PT) UT DP)"mN"))
;
; variable for output to file
;
(setq OUT1$ (strcat (rtos (car PT) UT DP)))
(setq OUT2$ (strcat (rtos (cadr PT) UT DP)))
;
(command "TEXT" (polar PT 0 TXTSZ) TXTSZ "0" VAL1$ "text" "" VAL2$)
;
; get insertion point while in loop
;
(write-line (strcat" " OUT1$ " " OUT2$ " " "0") fvar)
;
(setq PT
(getpoint "\n Please pick POINT to ID and label with TEXT... (hit Enter when done) "))
) ; end while
;
; reset OSMODE
(close fvar)
;
(setvar "OSMODE" OS)
(setvar "clayer" currlay)
(setvar "textstyle" txtstyl)
(terpri)
) ; end defun
(princ "IDXY Loaded.... Command = IDXY \n")
(princ)
; end idxy.lsp
现在唯一要做的就是让用户选择一个点编号,并让它在每次选择一个点时增加一个,你有什么想法吗?
我已经用(setq pno(+pno 1))进行了实验,但我不确定它应该具有什么功能,以及(老实说)确切地如何应用它。
干杯 您真的需要额外的选项,如“尾随零如何或ide”和“使用cientificecarchitectngract的单元类型:”?我改变了我的旧例程,现在它绘制点数并将其写入文件。
(defun c:oxy(/ fPt oldEcho oldNum dFlc dDec fVar cX cY cNum *error*)
(defun *error*(msg)
(setvar "CMDECHO" 1)
(if fVar(close fVar))
(princ)
); end of *error*
(princ(strcat "DIMSCALE="(rtos(getvar "DIMSCALE"))" "
"DIMLFAC="(rtos(setq dFlc(getvar "DIMLFAC")))" "
"DIMDEC="(rtos(setq dDec(getvar "DIMDEC")))" "
); end strcat
); end princ
(setvar "CMDECHO" 0)
(if(= 0(getvar "USERI3"))(setvar "USERI3" 1)
); end if
(setq cNum(getint(strcat "\nSpecify first point number <"
(itoa(getvar "USERI3")) ">: ")))
(if cNum (setvar "USERI3" cNum))
(setq fVar(open(strcase(strcat(getvar "DWGPREFIX")
(getvar "DWGNAME") ".xyz")) "a"))
(while
(setq fPt
(getpoint
(strcat "\nSpecify point or Right-Click to Quit <"(itoa(getvar "USERI3"))">: ")))
(if(vl-cmdf "_.dimordinate" fPt "_t"
(strcat
"["(itoa(getvar "USERI3"))"]" "\\P"
(setq cX(rtos(* dFlc(car fPt))2 dDec)) "mE"
"\\X"
(setq cY(rtos(* dFlc(cadr fPt))2 dDec)) "mN"
); end strcat
pause
); end vl-cmdf
(progn
(write-line (strcat " " cX " " cY " " "0")fVar)
(setvar "USERI3"(1+(getvar "USERI3")))
); end progn
); end if
); end while
(close fVar)
(setvar "CMDECHO" 1)
(princ)
); end of c:oxy
(princ "\nType OXY to tag coordinates ")
它使用标准DIM坐标标注,并通过标准标注变量DIMSCALE控制标注比例,DIMLFAC控制测量比例,DIMDEC控制小数位数。 这是一个很好的常规ASMI,但严格来说,我可以指出下面这行有一个轻微的拼写错误吗
(写入线(strcat“cX”cY“0”)fVar)
可以将计数数变量分配给USERR1吗?这样在以后打开图形时,这些数字就会知道最后一个使用的是什么,下一个数字就会从那里继续,而不是从1开始 谢谢你抓住了这个错误。现在“USERI3”系统变量中的当前数字。这是同情但非专业的,我应该使用字典而不是“USERXX”变量。但是我今天没有更多的时间去做。 我知道编辑大师的作品是异端,但如果你改变这行
(写入线(strcat“cX”cY“0”)fVar)
对于这个
(写入行(strcat(itoa(getvar“USERI3”))”,“cX”,“cY”,“0”)fVar)
然后输出为csv格式,带有点编号、东距、北距和高程(设置为零),非常适合上传到全站仪
所有的努力都是由ASMI完成的-谢谢 谢谢你Eldon。对于*。csv我认为:
(setq fVar(open(strcase(strcat(getvar "DWGPREFIX")
(getvar "DWGNAME") ".csv")) "a"))
很高兴帮助你。 谢谢各位,
我已经稍微调整了ASMI的肉饼,以符合我的目的,现在有一个例行程序来做我需要的一切。如果有人感兴趣,我已经附上了我完成的代码:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; OXY.LSP
; This routine is designed to display coordinate data on screen with a
; leader within a new layer and output data to a file for upload to a
; Total Station for setout.
;
; Example Run :
; Trailing Zeros how or ide ?
; Specify first point number: <do so>
; Specify point or Right-Click to Quit <do so>
;****** continues until mouse left click ******
; Specify point or Right-Click to Quit <do so>
;Lsp routine based on one supplied by ASMI on Cadtutor
;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
(defun c:oxy(/ fPt oldEcho oldNum dFlc dDec DMZ fVar cX cY cNum *error*)
;
(defun *error*(msg)
(setvar "CMDECHO" 1)
(if fVar(close fVar))
(princ)
); end of *error*
;
;Routine sets output variables
;
(princ(strcat "DIMSCALE="(rtos(getvar "DIMSCALE"))" "
"DIMLFAC="(rtos(setq dFlc(getvar "DIMLFAC")))" "
"DIMDEC="(rtos(setq dDec 3))" "
); end strcat
); end princ
;
;Routine creates new layer, sets textstyle and inserts data into it
;
(setq OS (getvar "OSMODE"))
(setq currlay (getvar "clayer"))
(setq txtstyl (getvar "textstyle"))
(command "style" "UTM" "romans" "0" "1" "0" "N" "N" "N")
(command "Layer" "M" "Coords" "S" "Coords" "")
;
; set trailing zeros to on or off
;
(initget 1 "S H")
(setq DMZ
(getkword "\nTrailing Zeros how or ide ? : "))
(cond ((= DMZ "S")(setq DMZ 3))
((= DMZ "H")(setq DMZ )
) ; end cond
(setvar "DIMZIN" DMZ)
;
;
;
(setvar "CMDECHO" 0)
(if(= 0(getvar "USERI3"))(setvar "USERI3" 1)
); end if
;
; Specify point number to start
;
(setq cNum(getint(strcat "\nSpecify first point number <"
(itoa(getvar "USERI3")) ">: ")))
(if cNum (setvar "USERI3" cNum))
;
; Create new file and open for writing
;
(setq fVar(open(strcase(strcat(getvar "DWGPREFIX")
(getvar "DWGNAME") ".xyz")) "a"))
(while
(setq fPt
;
; Click point/s on screen
;
(getpoint
(strcat "\nSpecify point or Right-Click to Quit <"(itoa(getvar "USERI3"))">: ")))
(if(vl-cmdf "_.dimordinate" fPt "_t"
(strcat
"["(itoa(getvar "USERI3"))"]" "\\P"
(setq cX(rtos(* dFlc(car fPt))2 dDec)) "mE"
"\\X"
(setq cY(rtos(* dFlc(cadr fPt))2 dDec)) "mN"
); end strcat
pause
); end vl-cmdf
(progn
;
;Write to file
;
(write-line (strcat (itoa(getvar "USERI3")) "," cX "," cY "," "0")fVar)
(setvar "USERI3"(1+(getvar "USERI3")))
); end progn
); end if
); end while
(close fVar)
;
;Reset to original settings
;
(setvar "OSMODE" OS)
(setvar "clayer" currlay)
(setvar "textstyle" txtstyl)
(setvar "CMDECHO" 1)
(princ)
); end of c:oxy
(princ "\nType OXY to tag coordinates ")
再次干杯
页:
[1]
2