乐筑天下

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

[编程交流] Special charector \ (92) ... (

[复制链接]

8

主题

22

帖子

14

银币

初来乍到

Rank: 1

铜币
40
发表于 2022-7-5 19:45:20 | 显示全部楼层 |阅读模式
G'day all,
Im trying to have the \ character in a string using (chr 92) but (chr 92) returns two backslashes \\.
 
 
The function is for storing some field code in a string so \\ wont cut it.
 
 
Anyone have any idea how I can store \ in a string or why (chr 92) behaves in this way.
 
 
Thanks
回复

使用道具 举报

8

主题

22

帖子

14

银币

初来乍到

Rank: 1

铜币
40
发表于 2022-7-5 19:52:53 | 显示全部楼层
Managed to figure it out by using Unicode instead of ASCII
回复

使用道具 举报

17

主题

1274

帖子

25

银币

后起之秀

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

铜币
260
发表于 2022-7-5 19:57:26 | 显示全部楼层
 
The backslash allows special characters including itself used in strings to simply be string characters.  When writing lisp for a field \" puts " as a character in a string and \\ puts \.
Ex:
  1. (strcat "%%")
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 20:01:48 | 显示全部楼层
Please read this explanation.
回复

使用道具 举报

8

主题

22

帖子

14

银币

初来乍到

Rank: 1

铜币
40
发表于 2022-7-5 20:06:38 | 显示全部楼层
Thanks
This was what I used to get around the problem
 
  1. (strcat "%%).Length " "\U+005C" "f " "\U+0022" "%lu6" "\U+0022" ">%")
 
Im having an issue now appending the variables to DXF codes on a block with attributes, Im getting 'nil' after entmod ... Fromobjid being the variable from the results above, any pointers?
 
  1. (command "-insert" "C:/conduit tag" pause "1" "1" "0")(setq        Tablesel (ssget "_L")Tablesel (ssname Tablesel 0)enlist(entget Tablesel)en1(entnext Tablesel)                en2(entget en1)en3(entnext en1)en4(entget en3)listget (append en4 (List (cons 1 fromobjid))))(entmod listget)
回复

使用道具 举报

1

主题

7

帖子

6

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 20:07:18 | 显示全部楼层
I have a question. Is there a possibility to write a field expression as superscript ie. in LeeMac's A2F Lisp (Area2Field) if you want to show suffix sqm as m2 (superscript 2) I tried with \U+00B2, {\H0.5x;2;}, also tried changing expression afterwards to extract exact field formatting (manualy and with LeeMac's FieldFormat lisp) but I haven't succeeded in doing what my intention was to put the code in original lisp with superscript result in suffix.
  Original Code:
  1. "%lu2%pr2%ps[A=,m2]%ct8[1e-004]"
Result:
A=4.04m2
 
  After editing MText, Field Edit:
From field expression (manually):
  1. "%lu2%pr2%ps[A=,m\\U+00B2 ]%ct8[0.0001]"
Result: A=4.04m2 (superscripted - I wrote it like this because it isn't shown on post preview)
From FieldFormatting (LeeMac's Lisp)
  1. "%lu2%pr2%ps[A=,m\\² ]%ct8[0.0001]"
But when I paste code into Lisp, and reload app, use it again on same object it shows as:
A=4.04mU+00B2 or A=4.04m2 (not superscripted)
Please advise.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 20:13:43 | 显示全部楼层
 
It seems you have misunderstood our responses - there is no problem:
In AutoLISP one must use two backslash characters to obtain a literal backslash, otherwise the backslash is treated as an escape character.
 
Observe:
  1. _$ (progn (princ "\nThis is a single backslash \") (princ))This is a single backslash \
Therefore, the first half of your field expression can become:

[code]"%
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 20:16:21 | 显示全部楼层
 
Try changing the formatting code in my Areas to Field program to:
  1. (setq fmt "%lu2%pr2%ps[A=,m²]%ct8[1e-004]") ;; Field Formatting
回复

使用道具 举报

8

主题

22

帖子

14

银币

初来乍到

Rank: 1

铜币
40
发表于 2022-7-5 20:23:59 | 显示全部楼层
Thanks Lee,
I only have a basic command of Vanilla lisp, my Visual lisp (and .net) are on my wish list but day to day chargeable work leave me little time to invest in development, most of my routines are created from plagiarising things I find on forums like this.
 
 
I have all the ID, I was just struggling to edit the field, full code below...
 
 
  1. ;Create Fields from selected block values(defun c:ELPITField ( / Fieldinfo1 fromobjid toobjid polyselect layname blkloc)(Prompt "\nCreate Fields from selected block values\nYou must select the text in the FROM and TO Blocks\nfor the function to work correctly!!!");======Block location(setq blkloc (strcat LOCAL_LIB LOCAL_OFFICE "01_Common/Blocks/Electrical/"));======Store Field info(setq Fieldinfo1 (strcat "%%")(setq Fieldinfo3 (strcat "%%"));======Get object ID Text(setq fromobjid (car (nentsel "\nSelect Attribute text in the 'FROM' Pit!: "))fromobjid (vla-get-ObjectId (vlax-ename->vla-object fromobjid))fromobjid (itoa fromobjid)fromobjid (strcat Fieldinfo1 fromobjid Fieldinfo2));======Get object ID Text(setq  toobjid (car (nentsel "\nSelect Attribute text in the 'TOO' Pit!: "))toobjid (vla-get-ObjectId (vlax-ename->vla-object toobjid))toobjid (itoa toobjid)toobjid (strcat Fieldinfo1 toobjid Fieldinfo2));======Get object ID Polyline(setq polyselect (car (nentsel "\nSelect Joining polyline: "))polyselect (vla-get-ObjectId (vlax-ename->vla-object polyselect))polyselect (itoa polyselect)polyselect (strcat Fieldinfo3 polyselect Fieldinfo4));======Insert and add Values to block(setq layname (getvar "clayer"))(if (= nil (tblsearch "layer" "EL_Conduit_tag")) (command "-layer" "new" "EL_Conduit_tag" "s" "EL_Conduit_tag" "C" "190" "EL_Conduit_tag" "") (command "-layer" "s" "EL_Conduit_tag" "C" "190" "EL_Conduit_tag" ""))(setvar "attdia" 0)(command "insert" (strcat blkloc "conduit tag.dwg") (getpoint) "1" "1" "0" "ID" fromobjid toobjid Polyselect "" "" "" "" "" "" "" "" "" "" "" "" "" "" "")(setvar "attdia" 1)(command "-layer" "s" layname "")(princ)             ;clean);defun(princ)
 
 
Ill 'start' investigating a VL solution, thanks for the guidance, but this 'rough' work around is doing the trick
回复

使用道具 举报

1

主题

7

帖子

6

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 20:25:29 | 显示全部楼层
Thx Lee, I already tried that but it gives me m2 result not m². Maybe is due to textformatting or ANSI coding that can't show superscript 2 (?), and if I save with Unicode coding upon lisp load it gives me an error:
  1. ; error: bad character read (octal): 0
With UTF-8, or BigEndian it gives some "A" charachter or the same error,
Bottom line can't show m² tried editing with LispEditor, Notepad, Notepad++...
 
 
If I'm stealing post, sorry jnky, I will start a new thread, thought that backslash would solve my superscript problems.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-12 01:10 , Processed in 1.100710 second(s), 72 queries .

© 2020-2025 乐筑天下

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