Start a new topic

mgGetParamBlock returns null (mgExecute usage in C)

Original Post by: 3265984 Tue May 20 21:18:42 2014


Below is the example given in the documentation for the usage of mgExecute.


// create a parameter block for the Calculate Shading command

// the parameter block is initialized with default values

mgparamblock paramBlock = mgGetParamBlock ("Calculate Shading");


// set the values for each parameter in the block

mgParamSetDouble (paramBlock, "Angular Tolerance", 89.0);

mgParamSetDouble (paramBlock, "Sampling Tolerance", 0.01);

mgParamSetString (paramBlock, "Shading Model", "Lit");

mgParamSetBool (paramBlock, "Triangle Area Weighting", MG_FALSE);

mgParamSetBool (paramBlock, "Update Vertex Colors", MG_TRUE);

mgParamSetBool (paramBlock, "Update Vertex Normals", MG_TRUE);

mgParamSetBool (paramBlock, "Use Face Color Intensities", MG_TRUE);


// execute the Calculate Shading command using the parameters set

mgExecute ("Calculate Shading", paramBlock)


I have many other elements working without issue (mgInit, mgOpenDb, mgWalk, etc.). However, when I call mgGetParamBlock("Calculate Shading"), it returns null every time.


Are there other steps that need to be taken to get this working?


Thanks


Original Post by: ChrisRogers Tue May 20 21:36:58 2014


I just tested this on my machine (using scripting because it is faster)... everything looks like it is working fine.


Let me throw a long shot out there...


First, I notice that this is your first post. I'm not sure how experienced you are with the api. Are you by chance trying to run this tool outside of Creator? IE stand-alone? If so, you need to know that this command cannot be ran stand-alone. It requires the Creator UI and plugins since it directly communicates with creator to perform the task.


If not, then what happens when you use the script version inside creator if you place a print paramBlock directly after the mgGetParamBlock statement.


does the print statement show a null address this way?

Original Post by: 3265984 Wed May 21 13:40:12 2014


Okay. That makes sense. I am running a stand-alone application.


EDIT: Disregard what is below. I see the option for running batch operations using Creator Pro.


I do have one more question then about making a plugin. Is there a way to automate opening files from within the plugin so that operations (like the one above) can be performed on a batch of files. Or do you have to manually open/close each file before running your script?


Thanks

Original Post by: SteveThompson Wed May 21 22:20:17 2014


I do have one more question then about making a plugin. Is there a way to automate opening files from within the plugin so that operations (like the one above) can be performed on a batch of files. Or do you have to manually open/close each file before running your script?


From your "edit" I realize you've discovered Batch Run Script in Creator Pro but I did want to answer your original question nonetheless.


A plugin can call mgOpenDb, mgWriteDb, mgSaveAsDb and mgCloseDb, so yes you could automate a process in your plugin that opens, edits and saves multiple databases. We know this can work because that's exactly what Batch Run Script does in Creator. Batch Run Script is, itself, a plugin ;-).

Original Post by: 3265984 Thu May 22 14:02:01 2014


# Cannot perform the mgExecute when opening using mgOpenDb

#db = mgOpenDb("d:/temp/input.flt")


# Works fine when the file is already opened in the editor by the user

db = mgGetCurrentDb()


mgMostDetail(db)


paramBlock = mgGetParamBlock ("Calculate Shading")

mgParamSetDouble (paramBlock, "Angular Tolerance", 25.0)

mgParamSetDouble (paramBlock, "Sampling Tolerance", 0.01)

mgParamSetString (paramBlock, "Shading Model", "Lit")

mgParamSetBool (paramBlock, "Triangle Area Weighting", MG_FALSE)

mgParamSetBool (paramBlock, "Update Vertex Colors", MG_TRUE)

mgParamSetBool (paramBlock, "Update Vertex Normals", MG_TRUE)

mgParamSetBool (paramBlock, "Use Face Color Intensities", MG_TRUE)

mgExecute ("Calculate Shading", paramBlock)


Is there a way to mgExecute an "Open" editor command to open the file in the editor? It appears that the calculate shading operation only works when the file is loaded in the editor.


Is there a way to perform a "Save" mgExecute operation as well when our operations have completed?

Original Post by: SteveThompson Thu May 22 16:34:24 2014


Sorry, I should have added a caveat to my previous response. While you can run OpenFlight Script commands on a db that has been open by mgOpenDb in your plugin (or script), you can only call mgExecute (Creator Script) on files that the user has open in the Creator desktop. i.e.,mgExecute cannot be called on dbs that have been opened by mgOpenDb in your plugin/script.


So to answer your question, there is no function in OpenFlight Script to open a file onto the Creator desktop. However you can use an os function in Python to do this. One such function is os.startfile as shown in this example:


import os

filepath = "C:/db/test.flt"

os.startfile(filepath)


Note however I am not aware of a corresponding "close" function you can use to subsequently close the file and get it off the Creator desktop.


As you might surmise, Creator Script is primarily geared to work on single, open files in Creator. OpenFlight Script, on the other hand (excluding mgExecute) is geared to work on both individual files in Creator and on batch files in stand-alone program environments.

Login to post a comment