Home Technical Talk

[MAXScript] Accessing Snap Angle variable in SnapMode struct?

polycounter
Offline / Send Message
Justo polycounter
I was trying to make a toggle function between different snap angle values, but much like this thread says from 2008, there isn't a variable listed in the Max documentation under the snapMode struct page, nor does the MaxListener pick anything up.

Is there a way to modify this value by script nowadays, or no there's been no change at all regarding the situation?

Replies

  • monster
    Offline / Send Message
    monster polycounter
    Looks like they tried to expose it with MaxPlus python api. But I can’t get it to work. 

    help.autodesk.com/view/3DSMAX/2016/ENU/?guid=__py_ref_class_max_plus_1_1_snaps_html

  • Pac_187
    Offline / Send Message
    Pac_187 polycounter lvl 11
    Lucky you! I just crafted something for @Olli. a few days ago :)

    global snapManager<br>struct snapManager<br>(<br>	private<br>	maxglobal,<br>	ip,<br>	<br>	public<br>	fn GetAngleSnap = <br>	(<br>		this.ip.ASnapStatus > 0 -- return value<br>	),<br>	<br>	fn SetAngleSnap state = <br>	(<br>		if not isKindOf state BooleanClass then throw "Supplied value is not a boolean!"<br>		if state then<br>		(<br>			if not this.GetAngleSnap() then this.ip.ToggleASnap()<br>		)<br>		else<br>		(<br>			if this.GetAngleSnap() then this.ip.ToggleASnap()			<br>		)			<br>		OK -- return value		<br>	),<br>	<br>	fn GetSnapAngle =<br>	(<br>		this.ip.SnapAngle_ -- return value<br>	),<br>	<br>	fn SetSnapAngle ang = <br>	(<br>		if not isKindOf ang Number then throw "Supplied value is not a number!"<br>		this.ip.SnapAngle_ = ang as float -- return value	<br>	),<br>	<br>	on create do<br>	(<br>		this.maxglobal = (dotNetClass "Autodesk.Max.GlobalInterface").Instance<br>		this.ip = maxglobal.COREInterface7<br>	)<br>)<br><br>::snapManager = snapManager() -- global singleton instance<br><br>
    Place it in your startup script folder and then you can use it like this:
    ::snapManager.GetAngleSnap() -- is angle snap active?<br>::snapManager.SetAngleSnap true -- activate/deactivate angle snap<br>::snapManager.GetSnapAngle() -- current snap angle value<br>::snapManager.SetSnapAngle 5 -- set new snap angle value<br>


  • Justo
    Offline / Send Message
    Justo polycounter
    @monster Thank you for replying Juan, you're always helping me out with my MXS woes and I really appreciate it.

    @Pac_187 My oh my, what black magic is this? How did you do it? Forgive me but the details escape me as I'm a beginner when it comes this subject. I know by placing this in my startup folder Max will read these functions and I'll be able to use them when writing code, but I wonder how inside those functions of yours you're accessing the parameter of the snap angle. 

    Are these the lines responsible for this?
    this.maxglobal = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
    this.ip = maxglobal.COREInterface7
    
    I see stuff here that I'm not used to dealing with. I see dotNetClass, which in my mind is "okay son we're doing hardcore programming now" and in the docs is something about more classes, objects and methods that were made because some ActiveX (?) stuff got obsolete when transitioning into 64 bits. 

    I also see COREInterface7, which I can't find anything on in the docs. 

    If you or anyone else feels like talking a bit about these, feel welcomed to do so :) I haven't tested your code yet, but I will tomorrow!


  • Justo
    Offline / Send Message
    Justo polycounter
    Yeah, the functions worked like a charm, and making a toggle script was super easy.

    5if not snapManager.GetSnapAngle() == 90 then 
            snapManager.SetSnapAngle 90
    else
    	snapManager.SetSnapAngle 


    Thank you so much Pac. If you feel like explaining any day what those two lines do, or how can I find out for myself, I'd appreciate it very much. Anyway, thanks again! 
  • Pac_187
    Offline / Send Message
    Pac_187 polycounter lvl 11
    Hey, haven't logged in for some time so didn't see your response, sorry.
    In simple terms I'm making use of the 3ds Max SDK using the .NET wrapper which has been released quite some time ago (Max 2012?!).
    Using the COREInterface you get access to some part of 3ds Max internals and can interact with stuff that's not exposed to the UI or Maxscript.

    So yea, as you guessed this can go a bit deeper than just scripting in maxscript.
  • Justo
    Offline / Send Message
    Justo polycounter
    @Pac_187 Hey man, sorry for bothering you with what must be a very obvious thing, but I can't pinpoint the problem. With the simple operation I posted above, I'm getting an error when using the snapManager.GetSnapAngle function.

    Unknown property. "GetSnapAngle" in undefined

    If I use the function in the Maxscript listener it works just fine, and somehow, after doing what I still don't know what, the function starts working normally again. But generally speaking, at least as soon as you open Max, the thing will fail. Got any ideas?

  • Pac_187
    Offline / Send Message
    Pac_187 polycounter lvl 11
    Hey @Justo, are you calling it with the two colons infront of it? Like in the examples above?
    This is important, it will force maxscript to look for the variable in the global scope.
  • Justo
    Offline / Send Message
    Justo polycounter
    Yeah, it was simple as that. Haha, thanks Pac, didn't know the two colons actually had a use in there.
Sign In or Register to comment.