Trouble with generating a fuselage and editing the cross section ParmVal's

172 views
Skip to first unread message

bsa...@terrafugia.com

unread,
Aug 2, 2016, 10:53:15 AM8/2/16
to OpenVSP
Hello,

I have written a short script (actually, it's a Python script reading in an NDARC .geom file and creating a VSP script of the NDARC output, if folks here are familiar with that code), but I am having trouble with the basics of generating a fuselage and editing the various cross section parameters.  

I have:

void main()
{
    string fid = AddGeom( "FUSELAGE", "" );                                              // Add Fuselage
string xsec_surf = GetXSecSurf( fid, 0 );                  // Get Surf object of fuselage
int num_xsecs = GetNumXSec( xsec_surf );          // Find out how many cross sections 
for( int i = 1; i < num_xsecs - 1; i++)
{
string xsec = GetXSec( xsec_surf, i );                 // Create a variable for the current Xsec
ChangeXSecShape( xsec_surf, i, XS_GENERAL_FUSE );        // Change the xsection to general fuse
SetParmVal( fid, "Height", xsec, 6.0);                                 // Set the xsection height
}
}

The SetParmVal does not seem to change the height, although the script does not error out.  Hardcoding the SetParmVal line to read:

SetParmVal( fid, "Height", "XSecCurve_1", 6.0); // Set the xsection height

Does not change the height to 6 either.  

Any help would be greatly appreciated.  Thank you!

Bryan Sandoz


Rob McDonald

unread,
Aug 2, 2016, 11:38:57 AM8/2/16
to ope...@googlegroups.com
Bryan,

Without a chance to dig in deep right now, I suspect that you need to
force an Update() at the end of your script.

When working from the API or scripting, VSP doesn't update when every
parameter is set -- that would slow the script down a lot. Instead,
you change a bunch of parameters and then must manually force an
update before you do anything else with that geometry.

Let me know if that doesn't work and I'll try to dig deeper.

Rob
> --
> You received this message because you are subscribed to the Google Groups
> "OpenVSP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to openvsp+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

bsa...@terrafugia.com

unread,
Aug 2, 2016, 1:13:39 PM8/2/16
to OpenVSP
Hello Rob,

Thanks for the help!  I added an Update(); to the code and it didn't seem to make a difference, it still doesn't change the height.  I have added a Print(xsec); in the hopes that it would show "XSecCurve_1" but alas it shows a string of letters (KLDAISSVJJ).  I was hoping I could drill down using GetParm to make sure the parameter was actually valid for the XS_GENERAL_FUSE type.    

Best,
Bryan

Rob McDonald

unread,
Aug 2, 2016, 3:00:30 PM8/2/16
to ope...@googlegroups.com
Ok,

Since you are working with XSecs, things are a little tricky -- since
there are a variable number of them, their parameters are buried a
level deeper than just a geom. When you are trying to find your
parameter, you are passing the fuselage ID, it would potentially
return a bunch of heights...

Instead, you want to check out the dedicated XSec related calls...

string parmid = GetXSecParm( xsec, "Height" );

Then you should be able to set the parameter value directly from the id.

Rob

bsa...@terrafugia.com

unread,
Aug 2, 2016, 4:01:33 PM8/2/16
to OpenVSP
Hello Rob,

Thanks!  I tried that and it doesn't seem to print anything for some reason.  I did however use that to get the parmid and then try and set the parmid directly rather than using group name, etc.  So now I have:

void main()
{
    string fid = AddGeom( "FUSELAGE", "" );             // Add Fuselage
string xsec_surf = GetXSecSurf( fid, 0 ); // Get Surf object of fuselage
int num_xsecs = GetNumXSec( xsec_surf ); // Find out how many cross sections 

for( int i = 1; i < num_xsecs - 1; i++)
{
string xsec = GetXSec( xsec_surf, i ); // Create a variable for the current Xsec
ChangeXSecShape( xsec_surf, i, XS_GENERAL_FUSE ); // Change the xsection to general fuse
string parmid = GetXSecParm( xsec, "Height" ); // Collect the xsection height variable
SetParmValUpdate( parmid, 6.0); // Set the xsection height
Print(parmid);
}
    
Update();

Unfortunately it doesn't seem to have changed the height, and still isn't printing the parmid.  Could I take it to mean that that parmid is not a function of xsec?  I tried to used Design Variables to get the right hierarchy. 

It should be Group = "XSecCurve_1", Parm "Width".  Using the above GetXSec line, is my variable xsec now a group, like "XsecCurve_1"?

Thank you,
Bryan

Rob McDonald

unread,
Aug 2, 2016, 4:12:23 PM8/2/16
to ope...@googlegroups.com
Ok, this does what you want...

ChangeXSecShape also changes the 'pointer' that refers to any
particular XSec. Consequently, the string xsec you get out of GetXSec
is invalid one line later.

Switching those two lines makes everything do what you want.

VSP's scripting stuff uses an error stack -- that way you can check
errors if you want, or you can ignore them. You can check as you go,
or check all at the end. You probably want to add something like this
to the end of your script.

//==== Check For API Errors ====//
while ( GetNumTotalErrors() > 0 )
{
ErrorObj err = PopLastError();
Print( err.GetErrorString() );
}

Rob
test.vspscript

bsa...@terrafugia.com

unread,
Aug 3, 2016, 1:02:52 PM8/3/16
to OpenVSP
Thanks Rob, that fixed it! 

So, just for my edification, I think part of my confusion lies in the difference between xsec_surf and xsec.  I was assuming xsec_surf was a list of various xsecs, but it sounds like it may be more complex than that?

Thanks,
Bryan
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages