FW: Escaping a triple quoted string' newbie question

  • Thread starter Jules Stevenson
  • Start date
J

Jules Stevenson

Hello,

Apologies if the terminology in this email is a little incorrect, I'm still
finding my feet.

I'm using python to generate some script for another language (MEL, in maya,
specifically expressions). Maya runs python too, but unfortunately its
expression language still has to use the maya syntax.

If I pass the expression this code:

#runtime code [mel]
expRuntime="""float $pos[]=particleShape1.worldPosition;
setAttr ("heartPP_1_"+particleShape1.particleId+".tx") $pos[0];
setAttr ("heartPP_1_"+particleShape1.particleId+".ty") $pos[1];
setAttr ("heartPP_1_"+particleShape1.particleId+".tz") $pos[2];
"""
dynExpression (p, s=expRuntime, rad=1) #generate the expression

Then maya errors out, however if I pass maya an 'escaped' version:

expRuntime="""float $pos[]=particleShape1.worldPosition;\r\nsetAttr
(\"heartPP_1_\"+particleShape1.particleId+\".tx\") $pos[0];\r\nsetAttr
(\"heartPP_1_\"+particleShape1.particleId+\".ty\") $pos[1];\r\nsetAttr
(\"heartPP_1_\"+particleShape1.particleId+\".tz\") $pos[2];" -rad
particleShape1;"""

Then all is well. My question is, is there any way to convert the first
variable example to the second? It's a lot easier to type and on the eye.

Tia, Jules
 
D

Duncan Booth

Jules Stevenson said:
Hello,

Apologies if the terminology in this email is a little incorrect, I'm
still finding my feet.

I'm using python to generate some script for another language (MEL, in
maya, specifically expressions). Maya runs python too, but
unfortunately its expression language still has to use the maya
syntax.

If I pass the expression this code:

#runtime code [mel]
expRuntime="""float $pos[]=particleShape1.worldPosition;
setAttr ("heartPP_1_"+particleShape1.particleId+".tx") $pos[0];
setAttr ("heartPP_1_"+particleShape1.particleId+".ty") $pos[1];
setAttr ("heartPP_1_"+particleShape1.particleId+".tz") $pos[2];
"""
dynExpression (p, s=expRuntime, rad=1) #generate the expression

Then maya errors out, however if I pass maya an 'escaped' version:

expRuntime="""float $pos[]=particleShape1.worldPosition;\r\nsetAttr
(\"heartPP_1_\"+particleShape1.particleId+\".tx\") $pos[0];\r\nsetAttr
(\"heartPP_1_\"+particleShape1.particleId+\".ty\") $pos[1];\r\nsetAttr
(\"heartPP_1_\"+particleShape1.particleId+\".tz\") $pos[2];" -rad
particleShape1;"""

Then all is well. My question is, is there any way to convert the
first variable example to the second? It's a lot easier to type and on
the eye.
Escaping the quotes doesn't change the string, so the only difference I can
see between your strings is that you have split the lines by carriage-
return+linefeed instead of just linefeed characters. If so:
s = expRuntime.replace('\n', '\r\n')
should have the desired effect.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top