In my project one of the requirement is to extract group of P's(call it block).
I want to repeat this block n number of times in output document.
P in the block contains some dynamic data which changes block by block.
I want to make copies of original P's so that I can add dynamic data into them and prepare a block.
P newP= Context.getWmlObjectFactory().createP();
newP = oldP;
However here, creating P and assigning old P to it assigns only reference of old P. How can I create a new P which will be similar to old P & still independent of it?
Use XmlUtils deepCopy method, at https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/XmlUtils.java#L1014
Related
Forgive me, I'm not a proper JS programmer and still getting my head around a lot of concepts.
Suppose one had a group of similar, 2-frame/2-state rollover movie clips nested inside a containing clip, which has the instance name "Map". Each clip uses a 4 digit ID number preceded by an "s" as an instance name – e.g., "s6566".
Suppose one then wanted to capture those respective instance names to define a variable, such that one small script could allow each of these movie clips to display their ID on rollover/active state (in this case "6566"), across multiple files.
Ultimately I have thousands of these little clips spread across several dozen documents, and it seems it should be fairly simple to grab each symbol's instance name/ID, strip off the "s" from the beginning (there because instance names can't begin with a numeral), and apply said ID as dynamic text to it's respective symbol's rollover/active frame.
Is there a method of achieving this goal? I wish I had some example code to include here, but I'm not quite sure how to begin, other than to lay out the problem thusly. Haven't yet been able to find any info on capturing instance names, and I'm not sure whether it's possible. Thanks.
Children of MovieClips are stored as references using their instance name. You can see the format in the exported library JS file. Note that Animate will convert some instance names to remove unsupported characters or duplicates.
Here is some untested pseudo-code to get you started.
// You can iterate a MovieClip and get the names
for (var name in someMovieClip) {
// Ignore anything not starting with an s
if (name.substr(0,1) != "s") { continue; }
// remove the s
var newName = name.substr(1);
// The child can be accessed using bracket-access with its name
var child = someMovieClip[name];
// The child should have text instances if it is set up how you described
// Set the text to the newName
child.textInstance.text = newName
}
Don't forget to update the stage after you make changes. If you already have Ticker set up to do that, it should update immediately.
I hope that helps. If you have follow-up questions, let me know.
I generated a number of dummy variables from a variable indicating the the relevant quarter, labelled quarter, with the following command:
tabulate quarter, generate(timeq)
This generates a set of dummy variables that range from timeq1 to timeq68.
I am trying to think about a way to rename these variables to change the names in the following way
timeq1 into 1995q1
timeq2 into 1995q2
timeq3 into 1995q3
timeq4 into 1995q4
...
timeq68 into 2011q4
As has been pointed out, this question sorely lacks a good MCVE. but an answer is possible.
Note first that the ambition to create variable with names beginning with 1 and 2 is futile as it is a basic rule that such names are not legal. However, a beginning underscore is allowed.
The problem of renaming requires, I think, at least one loop. In fact, it seems easier to back up and create the variables from scratch.
The first part of the code just creates a sandbox for play.
clear
set obs 68
gen quarter = yq(1994, 4) + _n
format quarter %tq
The second part is ad hoc code for the problem. Note that variable labels can take the form desired.
forval y = 1995/2011 {
forval q = 1/4 {
gen _`y'q`q' = quarter == yq(`y', `q')
label var _`y'q`q' "`y'q`q'"
}
}
I have the following code (PointLine and CalculatedLine both inherit Line):
For Each line As Lines.Line In lines
''Since both Point and Calculated lines are stored in the same list in the XML files,
''we need to force them back to their original type before using them
Select Case line.GetType()
Case GetType(Lines.PointLine)
line = DirectCast(line, Lines.PointLine)
line.init()''ERROR:'init' is not a member of 'PerformanceValidation.EngineValidation.Limits.Components.Lines.Line'
myLimitSeries.Add(line.series)
Case GetType(Lines.CalculatedLine)
line = DirectCast(line, Lines.CalculatedLine)
line.init(dataTable)''ERROR:'init' is not a member of 'PerformanceValidation.EngineValidation.Limits.Components.Lines.Line'
myLimitSeries.Add(line.series)
End Select
Next
The editor complains about line not being of type PointLine/CalculatedLine when i call line.init().
It's important that the original object be casted to either PointLine or CalculatedLine because I "initialize" them to contain calculated information that will be used later on. So basically, I don't want to create a new variable of type PointLine or CalculatedLine to act as a container for the casted Line.
I tried creating a new line of the appropriate type (exactly as I said I didn't want to above) and deleting the original line and adding the new one to the list but of course, it complains about the underlying list being modified.
Is there a way I can treat a Line as either a PointLine or CalculatedLine temporarily without affecting the list?
Thanks!
You don't need to create a new instance but you need to have a second variable of the right type for the reference. I don't understand when you say "delete", when you cast, you don't delete the instance since both variable are pointing at the same instance.
For Each line As Lines.Line In lines
Select Case line.GetType()
Case GetType(Lines.PointLine)
Dim linePoint As Lines.PointLine = DirectCast(line, Lines.PointLine)
linePoint.init()
myLimitSeries.Add(line.series)
Case GetType(Lines.CalculatedLine)
Dim lineCalculated As Lines.CalculatedLine = DirectCast(line, Lines.CalculatedLine)
lineCalculated.init(dataTable)
myLimitSeries.Add(line.series)
End Select
Next
No new instance are created here.
If you only call one function, you could always do.
For Each line As Lines.Line In lines
Select Case line.GetType()
Case GetType(Lines.PointLine)
DirectCast(line, Lines.PointLine).init()
myLimitSeries.Add(line.series)
Case GetType(Lines.CalculatedLine)
DirectCast(line, Lines.CalculatedLine).init(dataTable)
myLimitSeries.Add(line.series)
End Select
Next
You cannot re-type an item in a collection, because the type is set for the whole collection (in your example it's end of line 1).
I'd take a decision, whether the source data are in correct/required format or not. If you're not happy with the source format, I'd fix it there. If you need the source as is, I'd treat the lines in a layer above, but it would certainly require another collections.
Either you could convert one type of lines to another and put them into one collection or you could have one collection with some IDs and type, and two other collections for each type (you can probably use the source collections then).
Very new to python - just started actually using it yesterday. I'm running a for loop that scans a text file and copies specific parts of it into variables that will then be put into a class "post". I want to create a new post at the bottom of the loop, named "post0", "post1", and so on, corresponding with the number of times the for loop has been run. This is what I'm trying to use:
postname = globals()['post%s' % s]
And I currently am trying to have it print the name of the post every time it creates one with a simple print(postname). 's' is the variable the for loop runs off of, if that makes sense. It starts at 0 and runs up to the number of lines in the text file, currently 424.
When I run the code, it returns "KeyError: post0". What am I doing wrong?
Also, reading around here it seems that creating variables this way is bad practice. If there is a more efficient way to do it I'd be happy to try that instead, but I'd also like to know how to make this method work just so I understand the concept. Thanks.
Edit: Problem solved! See my answer below.
I created a list postlist = [] outside of the loop, then inside the loop I append the list with a "post_" where "_" is the 's' variable. Looks like this:
postlist.append('post%s' % s)
Python is cool!
Writing a function in Lua, which creates two tables. I want the tables to be assigned to the value name with an x added, and one with a y added. For example if name was line, it would create two tables linex and liney, but I can't figure out how to do it. The following obviously doesn't work (and is just for display purposes) but how would I go about doing this?
function makelinep(x,y,minrand,maxrand,name,length)
name..x = {}
name..y = {}
Later I hope to access "linex" and "liney" after values have been written.
If you want these in the global name space you would use
_G[name..'x']={}
_G[name..'y']={}
For a module you'd use _M in place of _G.