Jump to content

Diesel With Spaces


mwade93

Recommended Posts

I have discovered through my coding that diesel does not like spaces very much. I have been trying to use quotes but even those have not been functioning properly inside. Here is an example of what I mean:

 

setenv;users1;$M=$(getvar,ctab);

 

This works when there is no space in the layout name. However if a layout is B 17 x 11, it will set users1 to b as if there were no quotes around ctab.

 

So my question is, is there any way to set it where the name will be stored properly. Quotes around ctab and around the whole diesel do not work.

Edited by mwade93
Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • mwade93

    11

  • Tyke

    10

  • Tuns

    3

  • steven-g

    1

Top Posters In This Topic

In general it is recommended to use a semicolon instead of a space in the command string of the macro. It makes it a lot easier to understand and you can see how many returns/spaces you have. Using quotation marks around names with spaces should work without a problem, at least there has never been a problem in my command strings.

Link to comment
Share on other sites

I have problems each time I issue this string with or without the quotes. Its the name of the tab not the space in the string I am having issues with.

Link to comment
Share on other sites

The problem lies in the fact that there is space in the environment variable that you saved the layout name and when you call the environment variable the space is interpreted by AutoCAD as a return, as are all spaces entered in the command line. After you have saved the the layout name to the USERS1 environment variable you must when wanting to use this value assign the stored value to a normal variable and then use this variable in your DIESEL expression. Or try evaluating the text in the returned expression

$M=$(eval,$(getenv,ctab)

this would then treat the returned value as a text string.

Link to comment
Share on other sites

I tried what Tyke said and this is what happens (also you can see the layout names I am working with right now):

 

[ATTACH=CONFIG]44300[/ATTACH]

 

It just sits and waits here. This is how I used the code:

 

setenv;users1;$M=$(eval,$(getenv,ctab);

 

It seems to not like the eval part.

Link to comment
Share on other sites

I will do that when I get home, that will be blocked here on my computer at work. Thanks for your help though.

 

The article basically explains how to use triple quotes.

The quote-quote-quote

 

5cf21e7f36fd46008b9f249e98f21e8eUnfortunately has a lot of problems as soon as you create complicated macros. DIESEL uses a limited string space and you can easily crash AutoCAD by exceeding this limit.

Also the handling of quotes is not easy to understand, if ever. From the main text you know that

$(strlen,"Hello,world!")

returns 12, and

$(strlen,Hello,world!)

returns 5. But would you imagine that

$(strlen,Hello","world!)

also returns 12?

Even more strange is that quotes get lost during the DIESEL . What do you expext this expression to return?

$(substr,$(strlen,"Hello,world!"),1,1)

I would expect it to return 1, but certainly not 5! If you look at the macro trace, you see what happens:

Eval: $(SUBSTR, $(strlen,Hello,world!), 1, 1)

Eval: $(STRLEN, Hello, world!)

===> 5

===> 5

As soon as the string is passed to the substr DIESEL function, the quotes are lost. Therefore the strlen funktion consequently returns 5. To pass the quotes through the substr function to the nested strlen function, you need to add some more quotes:

$(substr,$(strlen,"""Hello,world!"""),1,1)

Eval: $(SUBSTR, $(strlen,"Hello,world!"), 1, 1)

Eval: $(STRLEN, Hello,world!)

===> 12

===> 1

Every level of nesting the number of quotes. Therefore you need to know in advance how many levels down you still need quotes. Suppose you want to add 1 to the result above. Now the correct DIESEL expression is:

$(+,1,$(substr,$(strlen,""""""""Hello,world!""""""""),1,1))

Eval: $(+, 1, $(substr,$(strlen,"""Hello,world!"""),1,1))

Eval: $(SUBSTR, $(strlen,"Hello,world!"), 1, 1)

Eval: $(STRLEN, Hello,world!)

===> 12

===> 1

===> 2

 

Have you tried using 'macro trace'?

Link to comment
Share on other sites

So here is what I have so far from my understanding of the article:

$M=$(substr,"""""B 17""""",1)^Z

 

Command Line

Command: Eval: $(SUBSTR, ""B 17"", 1, 4)

===> B 17

BLOCK

Enter block name or [?]: *Cancel*

 

This gives me variable as B if I use it in setenv.

 

So it is pulling it right but I am confused after that.

 

Here is another thing I tried:

 

^C^C^Csetenv;users1;"$M=$(substr,"""""B 17""""",1,4)";^Z

 

Command Line

Enter variable name: (Should be variable here)

Value : Eval: $(SUBSTR, ""B 17"", 1, 4)

===> B 17

 

Command: GETENV

Enter variable name: users1

$M=17""""",1,4)

 

This code works if I am on the model tab. This version pulls out mode because of the length of 4 I have it pulling.

 

^C^C^Csetenv;users1;$M=$(substr,$(getvar,ctab),1,4);^Z

Link to comment
Share on other sites

This code works if I am on the model tab. This version pulls out mode because of the length of 4 I have it pulling.

 

^C^C^Csetenv;users1;$M=$(substr,$(getvar,ctab),1,4);^Z

 

When using substr the first argument is the starting position and the second argument the length of the string to return. If you think that the maximum length of the layout name will be say 16 then use as the second argument a length of 20. It will not cause an error and you can be reasonably sure of always getting the whole layout name.

Link to comment
Share on other sites

Yes, I was just messing with those to learn them, it still does not work with my layouts that have spaces though, just pulls the part of the string that occurs before the space. Adding more and more quotes did not seem to cure the issue.

Link to comment
Share on other sites

Yes, I was just messing with those to learn them, it still does not work with my layouts that have spaces though, just pulls the part of the string that occurs before the space. Adding more and more quotes did not seem to cure the issue.

 

With the quotes, you need double quotes to start off with and then a quote for each level you go down, and of course balance the number of quotation marks at the end. By level they mean each time you have a $(...).

 

It's a public holiday here tomorrow so I'll see if I can get to test it on an AutoCAD LT 2014 computer at home. Don't give up.

Link to comment
Share on other sites

I wasn't planning on it. I have some more time this afternoon, I will keep working at it. It is probably something stupid that is going to work, it always is...lol :facepalm:

Link to comment
Share on other sites

I eventually got round to looking at this a bit closer and have come up with the solution. The following code works fine for me on layout names with spaces:

 

^C^C_setenv;Users1;$M=""""$(getvar,ctab)""""; 

 

Hope that it works for you too.

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