MEL Script Button deletes object if it exists - object

My MEL knowledge isn't great and I have created a small script that duplicates your object and brings it next to your main one. I want to make it like when you click the MEL button the object appears but when you click it again the object gets deleted (if exists). Any help would be great as I'm almost at the point where I'm gonna start hitting my head on the wall.
Thanks

Here's a bit of code that will delete an object if its found:
if (objExists("YOUR_OBJECT_NAME_HERE"))
{
delete("YOUR_OBJECT_NAME_HERE");
}

Let's create our test object. It's a nurbsSphere1:
sphere -p 0 0 0 -ax 0 1 0 -ssw 0 -esw 360 -r 1 -d 3;
if...else statement in MEL is quite simple. Use the following code to select and delete a nurbsSphere1 if it exists in your scene:
if(`objExists nurbsSphere1`) {
select nurbsSphere1;
delete nurbsSphere1;
} else {
warning("No NURBS Sphere exists");
}
To execute just several lines of MEL code (not all) in Script Editor, select all the lines you need and press ctrl+enter on a keyboard for execution.

Related

Remove text from string PowerShell

I´m vacation hangover and cannot wrap my head around an Powershell dilemma!
I´ve a script where I get the following output below which is saved to a variable $ScanOutput. Now I want to filter out and only keep the code after ExitCode= (Can be 500 or 0). How can I filter out everything before and after 500 (which can be other codes, not static).
#{StdOut=Checking for updates...
Determining available updates...
Check for updates completed
Number of applicable updates for the current system configuration: 0
No updates available.
Execution completed.
Program exited with return code: 500
; ExitCode=500; StdErr=}
Thanks in advance! Kind regards,
JN
You can simply use Select-String :
($ScanOutput | Select-String -Pattern 'ExitCode=(\d+)').Matches.Groups[1].Value
500
Many ways to skin a cat, assuming the delimiter ; is consistently placed. Might be nice to test which method is fastest:
($scanoutput -split ';')[1].Trim()
ExitCode=500
Since JNilsson came back and said that I actually was correct in my statement that it was hash table I will add back my answer to help others with similar problem.
The object
#{StdOut=Checking for updates... Determining available updates... Check for updates completed Number of applicable updates for the current system configuration: 0 No updates available. Execution completed. Program exited with return code: 500 ; ExitCode=500; StdErr=}
To get the ExitCode from the object simply make sure to assign it to a variable, in my case $hash then you can get the value by doing this:
$hash.ExitCode

Rexx Pull is not working with clrscrn after Displaying ispf Panel

Currently i am writing a rexx program in which i need to mask password input. I use this code to get my panel displayed:
address ispexec"libdef ispplib dataset id('my.pds')
address ispexec 'display panel(member)'
This works perfectly, and returns the password to a variable, in which i perform various checks on.
After that i continue on in my rexx program. the next function that occurs, is taking in input from the user by using Rexx's 'say' 'pull' method. This is where the weird error occurs.
I have to check user input again, if its invalid it loops back to the 'pull'. However, upon returning to the 'pull' instead of allowing the user to input data, the program gets the bottom of data symbol '***'. This then of course causes an infinite loop and the user then can't put in data.
I believe the cause is displaying the panel, then using clrscrn. Cause i can take out clrscrn and it works fine but data truncates on other pages. Or i can sacrifice masking the user password by NOT displaying the ispf panel and it works. But together it fails.
I was wondering what is happening and the potential fix.
Rexx Code i use to replicate the error after displaying the panel:
do while chk <> 'N'
clrscrn
do i = 1 to 5
say '-test'
end
pull chk
end
Result one with user input of ' '
-test
-test
-test
-test
-test
' ' <---- User inputs space, invalid entry, has to be 'N'
*** <-- for some reason hits bottom of data
Then it loops back with a result of:
-test
-test
-test
-test
-test
*** <---- automatically hits bottom of data
To reiterate, if i take out the clrscrn, bottom of data never occurs. but error too many times, data truncates to another page.
Put clrscrn back in, don't display an ispf panel. Code works flawlessly, bottom of data never occurs.
Panel code:
)PANEL
)ATTR
~ TYPE(INPUT) INTENS(NON) Pad(_)
! TYPE(TEXT) COLOR(RED) SKIP(ON)
)BODY WINDOW(80,24)
! CREATE YOUR PIN NUM
!--------------------------------------------
!
! ENTER YOUR PIN:~INP !
! CONFIRM PIN...:~INPT!
!
! MUST BE 4-DIGITS
)END
Another panel I also call before similiar situations:
)PANEL
)ATTR
~ TYPE(INPUT) INTENS(NON) Pad(_)
! TYPE(TEXT) COLOR(RED) SKIP(ON)
)BODY
! VERIFY YOUR IDENTITY
!--------------------------------------------
!
! ENTER YOUR PIN: ~Z !
)INIT
&ZEDSMSG = ''
&ZEDLMSG = ''
.ZVARS = '( INP )'
.ATTR(INP) = '&ATTRPIN'
)PROC
&RESP = .RESP
)END
The 3 asterisks indicate you have gone from full screen mode to line mode. The REXX say statement is line mode. You probably have a terminal using an alternate screen size (mod5, 62 x 160, etc). TSO VTAM will force the *** to protect against issues in changing between primary and alternate screen size. Use the following ISPF service instead of CLRSCRN
address ISPEXEC "CONTROL DISPLAY LINE START(1)"
This will put you in line mode and clear the screen. Your REXX routine works for me when I use the CONTROL DISPLAY LINE. This also tells ISPF that line mode has been entered which could also avoid screen corruption errors using CLRSCRN.

Fortran error check on formatted read

In my code I am attempting to read in output files that may or may not have a formatted integer in the first line of the file. To aid backwards compatibility I am attempting to be able to read in both examples as shown below.
head -n 3 infile_new
22
8
98677.966601475651 -35846.869655806520 3523978.2959464169
or
head -n 3 infile_old
8
98677.966601475651 -35846.869655806520 3523978.2959464169
101205.49395364164 -36765.047712555031 3614241.1159234559
The format of the top line of infile_new is '(i5)' and so I can accommodate this in my code with a standard read statement of
read(iunit, '(I5)' ) n
This works fine, but if I attempt to read in infile_old using this, I as expected get an error. I have attempted to get around this by using the following
read(iunit, '(I5)' , iostat=ios, err=110) n
110 if(ios == 0) then
print*, 'error in file, setting n'
naBuffer = na
!rewind(iunit) #not sure whether to rewind or close/open to reset file position
close(iunit)
open (iunit, file=fname, status='unknown')
else
print*, "Something very wrong in particle_inout"
end if
The problem here is that when reading in either the old or new file the code ends up in the error loop. I've not been able to find much documentation on using the read statement in this way, but cannot determine what is going wrong.
My one theory was my use of ios==0 in the if statement, but figured since I shouldn't have an error when reading the new file it shouldn't matter. It would be great to know if anyone knows a way to catch such errors.
From what you've shown us, after the code executes the read statement it executes the statement labelled 110. Then, if there wasn't an error and iostat==0 the true branch of the if construct is executed.
So, if there is an error in the read the code jumps to that statement, if there isn't it walks to the same statement. The code doesn't magically know to not execute the code starting at label 110 if there isn't an error in the read statement. Personally I've never used both iostat and err in the same read statement and here I think it's tripping you up.
Try changing the read statement to
read(iunit, '(I5)' , iostat=ios) n
You'd then need to re-work your if construct a bit, since iostat==0 is not an error condition.
Incidentally, to read a line which is known to contain only one integer I wouldn't use an explicit format, I'd just use
read(iunit, * , iostat=ios) n
and let the run-time worry about how big the integer is and where to find it.

How can I programatically copy and paste with source formatting in PowerPoint 2010?

I am currently automating some PowerPoint 2010 functions in Groovy using Scriptom - though this problem may be generic to any PowerPoint automation approach (ie more of a "VBA macro" issue than the particular environment I'm using?).
(Scriptom allows you to use ActiveX or COM Windows components from Groovy. Underneath the hood it uses the Jacob library (Java COM Bridge), I believe. The underlying code is similar to what I'd use in a VBA macro or other Microsoft automation component, and is based on the PowerPoint 2010 Object API.)
My current code works well and opens PowerPoint visibly and does a range of functions on it - except for a component where I "copy and paste" slides from one document to another, "keeping source formatting".
I have tried two attemps to do this copy and paste step, both leading to a different problem. I wonder if anyone has thoughts on solving either (or both?) of these problems:
Method 1: I use a basic "copy" and "paste" methods, suggested by various others, namely:
sourceSlide.Copy()
destinationSlide = destinationPresentation.Slides.Paste(slideIndex+i-1)
destinationSlide.Design = sourceSlide.Design
destinationSlide.ColorScheme = sourceSlide.ColorScheme
destinationSlide.FollowMasterBackground = sourceSlide.FollowMasterBackground
... and so on copying formats...
That is, I manually copy all the formats across to keep slide-formatting. This is the method used prior to PowerPoint 2010. I've actually got this working, however to copy the formats I loop over each slide in the "source" slidepack and do the copy/paste code above. In this loop, the following line (alone) is problematic:
destinationSlide.Design = sourceSlide.Design
This line runs incredibly slowly once the destination SlidePack has a large number of "Designs" in the SlideMaster. I am copying a source slide-pack of 19 slides, each of which has a different SlideMaster Design Theme (that's how it comes to me). This single line of code takes about 0.01 seconds for copying the first slide over, but by the time it comes to the final slide in the loop, the single line of code takes over 20 seconds to run each time. Thus, copying the first five slides might take <1 second, but the total 20 slides takes around 100 seconds in total, with all the latter slides taking longer and longer to run just this single line. The rest of the code races by!
The slow-down isn't linear, and gets even worse beyond 20 slides. It isn't related to the content on the final slide(s), but seems to be that as the number of SlideMaster "designs/themes" increases it slows exponentially to copy across the "sourceSlide.Design". I realise having a different "Design" object for each slide is a bit of a waste, but I don't own the initial source presentation, and often they do come to me like this, with just slight difference between the Designs for each slide. If I remove the "destinationSlide.Design" line the time it takes can reduce from 100+ seconds to around 1 second!
Method 2: In order to avoid this, and given I'm using PowerPoint 2010, I tried to use the following code, instead:
sourceSlide.Copy()
def destinationPresentation = objPpt.Presentations.Open(destinationFilename)
destinationPresentation.CommandBars.ExecuteMso("PasteSourceFormatting")
I believe this should provide direct access to PowerPoint 2010 "Paste with Source Formatting" functionality. However, this fails with a "null pointer exception" at the ExecuteMso("PasteSourceFormatting") line.
What am I doing wrong? Is there any way to speed up the slow line in Method 1? Why is method 2 not working at all? It looks like "destinationPresentation.CommandBars" is not null, but that the "ExecuteMso" line throws a null pointer exception.
Are there any other suggestions for efficiently "copy and paste" slides that should work in a reasonable time frame for 20-100 slides, even if there are multiple different designs/themes?
Thanks, in advance, for any ideas.
The problem with method 2 is I was using:
destinationPresentation.CommandBars.ExecuteMso("PasteSourceFormatting")
Whereas this should have been:
destinationPresentation.Application.CommandBars.ExecuteMso("PasteSourceFormatting")
Using this code, I no longer get the null pointer exception.
I've submitted this as an answer to assist anyone who makes a similar error in future.
That being said, I still find that the performance of this approach (method 2) is not significantly better than the manual "copy and paste formats" method (method 1). In both cases, the performance with "paste with source formatting" functionality is many, many times slower than a normal "paste" - and takes around 2 minutes to do the paste of about 20 slides (each with its own design template). This is reduced to less than a second if I use "destination formatting", or don't have each slide with its an individual design template.
This may just be an issue with PowerPoint 2010 performance, however, so I will accept this answer unless someone has more information that would provide a better solution to the performance aspect of the original query.
Not sure it helps, but you can do this sort of thing with Apache POI:
#Grab( 'org.apache.poi:poi-ooxml:3.10-beta1' )
import org.apache.poi.xslf.usermodel.XMLSlideShow
new File( '/tmp/Presentation1.pptx' ).withInputStream { p1 ->
new File( '/tmp/Presentation2.pptx' ).withInputStream { p2 ->
// Load our 2 presentations
inpptx = new XMLSlideShow( p1 )
outpptx = new XMLSlideShow( p2 )
// Add slide 1 from inpptx to the end of outpptx
outpptx.createSlide().importContent( inpptx.slides[ 0 ] )
// Save it out again to a 3rd presentation
new File( '/tmp/Presentation3.pptx' ).withOutputStream { out ->
outpptx.write( out )
}
}
}

using and(&&) operator in for loop in linux

01) I am trying to use the && operator in a for loop as shown below in the script. However this does not seem to work. I was not able to see the error generated in the terminal window, since it closes as soon as it runs in to an error. Could someone please tell me what I'm doing wrong?
#!/bin/bash
cd ~/Documents/DTI/
#subj and subj1 contain folders which are located in the DTI directory
subj="ARN MT"
subj1="ARNpre1 ARNpre2"
for [[s in $subj] && [s1 in $subj1]]
02) And as you can see in my "subj1", the first two entries start with the letters ARN which means that they are sub directories of ARN(located in a different place.Not in ARN main directory). So I also want to run a command in which, if subj1 contains subj then it must perform a certain command.For this purpose I wrote the following,
if [[ ${s1} == *"${s}"* ]];then
would this be the right way to do such operation?
I would greatly appreciate any help.
Thank you in advance.
I think by for [[s in $subj] && [s1 in $subj1]] you mean this:
for s in $subj; do
for s1 in $subj1; do
# do something
done
done
By nesting the for loops you'll loop through every possible combination of s and s1, which sounds like what you're trying to do in part 1 of your question.
However, I can't make sense of what you're talking about in part 2, so I can't help you there.

Resources