Jump to content

Difficult time with quotes


Bill Tillman

Recommended Posts

I'm finding this a bit perplexing...probably a simply solution. I have a C#.NET project that's going to open AutoCAD and send a command to it. The command is simple but it's long. So what I'm trying to do is concatenate all of it and pass it in the SendCommand.

string vAcadCmd = "(setq ";
vAcadCmd = vAcadCmd + "username \"" + myArray[0] | " \"";
vAcadCmd = vAcadCmd + "email \"" + myArray[1] | " \"";
vAcadCmd = vAcadCmd + "dim_a \"" + myArray[2] | " \"";
.
.  and so on through all 48 variables 
.

What I want to end up with is the string formatted like this:

(setq username "Person A" email "PersonA@usa.com" dim_a "11" ....etc

 

When I add vAcadCmd to the watch window in VS I see its value but is has all the "\" backslashes in it. I've tried it with the @ literal string as well and can't seem to grasp how to make the string format correctly to send it to AutoCAD.

Link to comment
Share on other sites

Your escaped quotes look fine but what is the or operator doing in there? ... | ?? Methinks it should be another +.

 

you could try using a variable string quotes = chr(34);

 

You may wish to build another array with the text and iterate through the variations. In any case it is "more properer" to build a string with the StringBuilder class and then call .ToString() on the final results.

 

Writing a C# app to send a Lisp command strikes me as kind of odd but that's mostly because I don't understand your aim.

 

Hope this helps

cheers

Link to comment
Share on other sites

More information is needed, Bill... Can you provide a sample list of your array's contents, desired before\after, etc.?

 

Far simpler to just break up the concatenation with myriad +, than to repeatedly set the same variable with another small + being added. Not sure what the pipe is doing in there either (as an 'if' test?)

 

 

 

Couple of good reads:

 

C# Convert Array, String

 

Getting and Putting Lisp Variables from .NET

 

 

 

Cheers

Link to comment
Share on other sites

Yes, excuse me the | should have been another +.

 

I'm just trying to create this string:

 

(setq username "myusername" email "myemailaddress@msn.com"...)

 

Just want to build a string which contains this setq command that will set the values for 48 different variables. Then I will use SendCommand from C# to have AutoCAD execute this command.

 

The array is just a ListArray containing strings and numbers, mostly text "Y" and "N" fields. And I need to place the array values inside of double quotes. It almost looks fine, when I write it to a text file using C# I get what I want but I don't use quotes in that code. It's when I'm building this string and watching it increase in size in the watch window I keep seeing this:

(setq username \"MyUserName \" email \"myemaladdress\"....

I don't know if the \ character is a property of seeing it in the watch window or if it's not escaping the \.

Link to comment
Share on other sites

Again, you've not posted enough code for us to determine the issue, so for the time being perhaps this:

 

string yourCommand "(setq username " + "\"myusername\"" + " email " + "\"myemailaddress@msn.com\"" + "...)";

Link to comment
Share on other sites

I don't know if the \ character is a property of seeing it in the watch window or if it's not escaping the \.

 

Neither; C# handles quotes within strings the same as LISP. :thumbsup:

Link to comment
Share on other sites

Thanks BlackBox for your patience on this. I've been out with an injury for the last two days. And again, the code I'm working with has loads of proprietary info in it so I have to redact so much in order to post it. Anyway...and BTW I should include here, this is a stand-alone program. I believe the official lingo for it is COM, meaning that it runs outside of AutoCAD. This code is for the automated process I've been running here and user input is not only disallowed, it's not possible because all this code runs in the background on a server deep inside of the LAN.

 

The pipe character you show in your post is actually the backslash character. And I'm seeing that backslash character when I check the value of the string in the watch window. Here's more of the code that I'm working with:

ArrayList myArray = new ArrayList();
myArray.Add("MyUserName");
myArray.Add("emaladdress@somewhere.com");
myArray.Add(42);
myArray.Add(53);
.
.
.  and so forth until all 48 fields are entered
.
.
// Now I need to concatenate a string variable to hold all 48 of those values in a setq command line to be executed by AutoCAD

vAcadCmd = "(setq ");
vAcadCmd = vAcadCmd + "username \"" + myArray[0] + "\" ";
vAcadCmd = vAcadCmd + "email \"" + myArray[1] + "\" ";
vAcadCmd = vAcadCmd + "length \"" + myArray[2] + "\" ";
vAcadCmd = vAcadCmd + "width \"" + myArray[3] + "\" ";
.
.  and so forth for all 48 variables
.
vAcadCmd = ")";

// Now open up an instance of AutoCAD and send the setq command to it

.  Standard C# code to open up Autocad goes here...
.
vAcadDoc = vAcadApp.Documents.Open("C:\Misc\MyAutoCADFile.dwg", true);
vAcadDoc.SendCommand(vAcadCmd)

Now, I'm not sure yet how to get the syntax on the SendCommand correct yet in C#. I do it all the time in VB.NET but that's not the trouble. The trouble I'm getting is when the string vAcadCmd is being created and I watch it grow in the watch window, step by step. The watch window shows me this for the value of vAcadCmd:

vAcadCmd "(setq username \"MyUserName" email \"emaladdress@somewhere.com\" "

I'm not sure why the backslashes are showing up in the value column in the watch window. I'm expecting to end up with a string like this. Note this is shortened because I didn't want to waste space with all 48 variables:

(setq username "MyUserName" email "emaladdress@somewhere.com" length 42 width 53).

Link to comment
Share on other sites

I'm still not getting the issue.

 

The backslash is correct syntax for concatenating a string with quotes inside of the string's own (outer) quotes.

 

Is the code not executing properly when passed to SendCommand()? What is the actual issue you're having here? *confused*

Link to comment
Share on other sites

Okay, a little further along with the testing reveals that the string is being sent to AutoCAD without the backslashes. Why they are showing up in the watch window is what I'm confused about. The string in AutoCAD command window appears like this:

(setq username "MyUserName@msn.com" eflag "email" dim_a 42 dim_b 48 dwgno "99999" ohs "N" ehs "N" ovs "N" evs "N" slamlock "N" rpl "N" cylock "N" safetychain "N" deletestaple "N" front "N" back "N" side "N" hoaside "N" acudor "N" skirt "N" slabdp 6 debrisfree "N" boltlock "N" hna "N" bitucoat "N" sidedrain "N" grating "N" shocks "N" finish 1 qnum "213111" oversize "N" afrm "1/4 EXTRUDED FRAME" cvrplt 1/4 FLOOR PLATE" rband "1/4 X 2 1/2 F.B." fband "1/4 X 2 1/2 F.B." sband "1/4 X 2 1/2 F.B." hoaband "1/4 X 2 1/2 F.B." numribs 2 rib "C3X2.43#"  numhinge 2 hingepn "PART #5" hoapn "PART #92" numshocks 0 numsprgs1 2 numsprgs2 2 hatchwt "82.234811" pdfsize "B" skirtflag "0")

 

Now, I can see that when I paste this into NotePad I've got some typos to deal with. When I corrected all the typos, AutoCAD handles the command with no sweat. So I've got some more debugging to do. Back later.

Link to comment
Share on other sites

Okay, I found all the bugs and the quote marks are finally under control...maybe. The trouble I'm having now is that I can't use the same syntax with C# that I did with VB when I used send command. The command is usually done with Chr(13) so I did my VB code like this

vAcadDoc.SendCommand("(load """ & LispPath & LispFileName & ".lsp"" ""The load failed"") " & LispCmd & Chr(13))

This works great but when I try to enter Chr(13) or Chr(anything) in C# it does not like it???

 

Ooops. I spoke too soon. It appears that AutoCAD will gladly accept a space as . When I added that to the send command it all works now.

Link to comment
Share on other sites

Ooops. I spoke too soon. It appears that AutoCAD will gladly accept a space as . When I added that to the send command it all works now.

 

This.

 

Glad you got it all sorted, Bill. :beer:

Link to comment
Share on other sites

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