Jump to content

Python plug-in with widgets (basic example)


_c_

Recommended Posts

About text alignments: you can set a plug-in object to respond to font and text size using 

 vs.SetObjectVariableBoolean(gPio_H, 800, True) 

but all other text properties, such as horizontal and vertical alignment, etc. must be coded and driven by parameters.

Link to comment

Explanation:

 

The plug-in needs to be event enabled: you do this in the Options tab of the Plug-in editor:

 

1341293943_Screenshot2021-03-29at06_18_48.thumb.png.7eb337d472c094f2a63fc1b1b33d2fd1.png

 

 

If you work on Python with external files, the plug-in needs to reload the code, so you must turn off caching during development:

 

1764448575_Screenshot2021-03-29at06_19_17.thumb.png.5854c3df18c44a5b3e414e48752d2bbc.png

 

 

Here I break down the events employed. There are bucketloads of events, you'll find them in the SDK: MiniCadHookIntf.h and it does take a lot of time to be comfortable with their usage. Some of them I have really no idea what they do, and believe me, I did spend an inordinate about of time on them. The two major files you might want to study are these, but there is far more (the SDK version is here just irrelevant):

 

1380862304_Screenshot2021-03-29at06_23_25.thumb.png.b7b4bcaf49fbdd228f3045419954a9b3.png

334621851_Screenshot2021-03-29at06_23_33.thumb.png.0ec18bc252e983e0260ec40a551853a1.png

 

The code for the plug-in runs a number of times (and double as much if the developer mode is on), vs.GetCustomObjectInfo is compulsory for fetching the needed basic variables:

(ok, gPio_N, gPio_H, gPioRec_H, gWall_H) = vs.GetCustomObjectInfo()

 

Every time the code runs, you must fetch the type of event involved and eventually do something during that event. vs.vsoGetEventInfo is compulsory for fetching event info:

(theEvent, theButton) = vs.vsoGetEventInfo()
# whereby theButton is a generic message

(theEvent, aMessage) = vs.vsoGetEventInfo()

 

  • Like 2
Link to comment
  • 1 month later...

I'm really thankfull to this post!

 

I'm doing a lot of try and error, but it works pretty fine! 🙂

 

On 3/29/2021 at 6:56 AM, _c_ said:

Warning: you will need to close and re-open your document to see widget groups display properly EVERY time you change something in the parameter index list (add, delete parameters)

I guess, a simple open and close the Editing-Window in the PlugIn Manager is working as well..

  • Like 2
Link to comment
  • 2 months later...

Nice share @_c_! Finally got my group widgets working after months of trial and error.

 

My widget indent calls were in the kObjOnWidgetPrep function not the kObjOnInitXProperties. (Funny that indentation works in kObjOnWidgetPrep without the Grouping)

 

Again, thank you and thank you.

Edited by twk
  • Like 1
Link to comment
  • 1 month later...

@Alexander Zemtsov,

4 hours ago, Alexander Zemtsov said:
def main():
	gDX = vs.Pwidth
	gDY = vs.Pdepth
	gDZ = vs.Pheigth

 

Pwidth, Pdepth, and Pheight are programmer defined parameters in the Plug-in object. The are displayed in the OIP at runtime (without the leading "P") and you use them to change the shape of the Plug-in object on the drawing. You can see all of the plug-in's "P" parameters by using the Plug-In Editor. In the code, they are effectively constants that are loaded before the code runs.

 

HTH,

Raymond

 

 

  • Like 3
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...