Jump to content

Special charector \ (92) ... (chr 92) returns \\


Recommended Posts

Posted

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

Posted

Managed to figure it out by using Unicode instead of ASCII

Posted
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

 

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:

(strcat "%<\\AcObjProp Object(%<\\_ObjId " (rtos obid 2 0) ">%).Area \\f \"%lu2%pr3%ps[±, Acres]%ct4%qf1%ct8[2.295684113865932e-005]%th44\">%")

Posted

Thanks

This was what I used to get around the problem

 

(strcat "%<" "\U+005C" "AcObjProp Object(%<" "\U+005C" "_ObjId ")

 

and also

 

(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?

 

(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)

Posted (edited)

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:

"%lu2%pr2%ps[A=,m2]%ct8[1e-004]"

Result:

A=4.04m2

 

After editing MText, Field Edit:

From field expression (manually):

"%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)

"%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.

Edited by muurr
Posted
This was what I used to get around the problem

(strcat "%<" "\U+005C" "AcObjProp Object(%<" "\U+005C" "_ObjId ")

and also

(strcat ">%).Length " "\U+005C" "f " "\U+0022" "%lu6" "\U+0022" ">%")

 

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:

_$ (progn (princ "\nThis is a single backslash \\") (princ))

This is a single backslash \

Therefore, the first half of your field expression can become:

"%<\\AcObjProp Object(%<\\_ObjId "

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?

 

(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)

 

Although theoretically possible to create a field using Vanilla AutoLISP, if you wish to entmake[noparse][x][/noparse] / entmod a Field, you will also need to entmake[noparse][x][/noparse] the extension dictionary attached to the annotation object housing the field expression, in addition to the ACAD_FIELD dictionary within this extension dictionary, the TEXT dictionary within the ACAD_FIELD dictionary, and each of the individual FIELD entities contained within the TEXT dictionary.

 

Therefore, it inevitably becomes easier to use the ActiveX methods of Visual LISP, which perform the above operations automatically.

 

Aside from the above, have you first obtained the Object ID of the object to use in the field expression?

Posted
Is there a possibility to write a field expression as superscript

 

Try changing the formatting code in my Areas to Field program to:

(setq fmt "%lu2%pr2%ps[A=,m²]%ct8[1e-004]") ;; Field Formatting

Posted (edited)

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...

 

 

;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 "%<[url="file://\\AcObjProp"]\\AcObjProp[/url] Object(%<[url="file://\\_ObjId"]\\_ObjId[/url] "))
(setq Fieldinfo2 ">%).TextString>%")
(setq Fieldinfo3 (strcat "%<[url="file://\\AcObjProp.16.2"]\\AcObjProp.16.2[/url] Object(%<[url="file://\\_ObjId"]\\_ObjId[/url] "))
(setq Fieldinfo4 (strcat ">%).Length [url="file://\\f"]\\f[/url] \"%lu2%pr0%ct8[1.05]\">%"))
;======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

Edited by jnky
UPDATE
Posted

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:

; 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.

Posted
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:

; 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++..

 

AutoLISP is only compatible with the ASCII (and extended ASCII) character set, and therefore Unicode characters must be represented using their code points (e.g. U+#### etc.) and you cannot save an AutoLISP file in Unicode format, else you will receive errors when the interpreter tries to read the file.

 

However, the character ² is part of the extended ASCII character set [noparse](character 178)[/noparse] and therefore should be compatible for use with AutoLISP.

 

Try the following instead:

(setq fmt (strcat "%lu2%pr2%ps[A=,m" (chr 178) "]%ct8[1e-004]")) ;; Field Formatting

Posted (edited)

I'm widening my knowledge about AutoLISP with your answers, thank you Lee! I didn't know that AutoLISP are only ASCII-able.

So, I tried with chr178 but it gave me another character. I figured out that's because my system is on Latin-2 ASCII due to language pack by default, which is different in extended part (where the superscript character is).

Than I changed 'Language for non-Unicode programs' in Windows (8.1) settings, Language, and - voila! Now it displays superscript 2 as you suggested.

I also changed that individual programs use their own language, and installed language pack that I need.

Thank you!

Now only my second question is un-answered: is there possibility to show text in superscript/subscript for field prefix/suffix via AutoLISP?

Edited by muurr
Posted
I'm widening my knowledge about AutoLISP with your answers, thank you Lee! I didn't know that AutoLISP are only ASCII-able.

So, I tried with chr178 but it gave me another character. I figured out that's because my system is on Latin-2 ASCII due to language pack by default, which is different in extended part (where the superscript character is).

Than I changed 'Language for non-Unicode programs' in Windows (8.1) settings, Language, and - voila! Now it displays superscript 2 as you suggested.

I also changed that individual programs use their own language, and installed language pack that I need.

Thank you!

 

You're welcome - I'm glad you were able to resolve it!

 

Now only my second question is un-answered: is there possibility to show text in superscript/subscript for field prefix/suffix via AutoLISP?

 

Since the field prefix/suffix content is fixed and since field expressions do not permit the use of MText formatting, I would instead suggest moving the prefix & suffix text outside of the field expression and surrounding these with the appropriate MText formatting codes.

 

For example, where my Areas to Field program is concerned, you would need to change the field formatting to:

(setq fmt (strcat "%lu2%pr2%ct8[1e-004]")) ;; Field Formatting

 

And then change line 94 of the program from:

str

to:

(strcat "A=" str "m{\\H0.7x;\\Syoursuperscripttexthere^;}")

Posted

Divine.

Thank you Lee for your knowledge!

Now I know the reason why I haven't succeeded with:

{\H0.5x;2;}

as I mentioned in post #6

I found on another thread about MText coding: http://www.cadtutor.net/forum/showthread.php?22036-VB-Automation-How-to-write-text-in-superscript-to-AutoCAD&p=140919&viewfull=1#post140919 tried different scenarios, and works.

Only thing is that with MText coding you cannot place superscript to look as you want it because if you set H0.3x maybe the size iz ok, but the vertical placement by main text doesn't look that good as it does with ASCII.

So size of 0.7x (0.65x) what you suggested is ideal for superscript.

Thank you once again!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...