Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

How to call SurroundsPoint(Point2 p) API function from maxscript

How to call SurroundsPoint(Point2 p) API function from maxscript

gastonDTKNS
Explorer Explorer
401 Views
5 Replies
Message 1 of 6

How to call SurroundsPoint(Point2 p) API function from maxscript

gastonDTKNS
Explorer
Explorer

Hi everyone,

I'm trying to test splines intersections and "hollows" by using some functions from the api inside maxscript. This example is based on a code found on internet but I'm not able to call SurroundsPoint(Point2 p), apparently I'm not able to pass a point2 value to that function.

Can someone help me with this? thanks a lot

(
  g = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
  inode = g.coreinterface7.getinodebyhandle $.inode.handle
  shp = ((inode.EvalWorldState (int currenttime) true).obj).shape_
  splines = for i=0 to shp.SplineCount-1 collect shp.GetSpline i
  
  for i=1 to splines.count do
  (
    format "isClockWise %\n" (splines[i].isClockWise)
    format "matID %\n" (splines[i].getMatID 1 )
    --without parameters the function is recognized
    format "SurroundsPoint %\n" ( splines[i].SurroundsPoint )
    --THIS GIVES AN ERROR
    --format "SurroundsPoint %\n" ( splines[i].SurroundsPoint [0,0] )
    format "Spline % is self-intersecting: %\n" i (splines[i].SelfIntersects)
    for j=i+1 to splines.count where splines[i].IntersectsSpline splines[j] do
    (
      format "Spline % intersects spline %\n" i j
    )
  )
)

 

0 Likes
Accepted solutions (1)
402 Views
5 Replies
Replies (5)
Message 2 of 6

MartinBeh
Advisor
Advisor

This seems to be incorrect?

shp = ((inode.EvalWorldState (int currenttime) true).obj).shape_
Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 3 of 6

gastonDTKNS
Explorer
Explorer

Honestly I don't know! I try to learn this kind of stuffs by comparing codes, I took this one from here
https://maxscriptbook.com/community/maxscript/Shape+Check%2C+or+finding+self+intersections+of+a+spli... 

several functions from Spline3d class seems to work except for SurroundsPoint(Point2 p)

I can't find any reference to read about using this from maxscript, so I really appreciate any clue about what should I look at

0 Likes
Message 4 of 6

MartinBeh
Advisor
Advisor
Accepted solution

OK, it looks like the .shape_ property is only available for some shape types. I found another forum thread on a similar topic: https://forums.autodesk.com/t5/3ds-max-programming/spline-normalize-2-extend-modifier-how-can-i-snap... where Denis shows how to use MakeBezier to get the shape for a Line object.

 

With that, I was able to get your SurroundsPoint call working:

 

-- create a new Point2 value with coordinates [1,2]
p = g.point2.create 1 2
-- shp is the current spline
shp.SurroundsPoint p

 

I don't know whether this actually does what you need, but at least it now returns "false" instead of an error. 

 

Hope this helps!

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 5 of 6

gastonDTKNS
Explorer
Explorer

Great!!! that was the answer, you defined the point2 value inside the GlobalInterface instance, it is working in both cases, thanks a lot!

It is for nothing specific right now, I'm just trying to understand the concept of using the interface

(
  g = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
  inode = g.coreinterface7.getinodebyhandle $.inode.handle
  shp = ((inode.EvalWorldState (int currenttime) true).obj).shape_
  splines = for i=0 to shp.SplineCount-1 collect shp.GetSpline i
  
  p = g.point2.create 0 0
  
  for i=1 to splines.count do
  (
    format "isClockWise %\n" (splines[i].isClockWise)
    format "matID %\n" (splines[i].getMatID 1 )
    --without parameters the function is recognized
    format "SurroundsPoint %\n" ( splines[i].SurroundsPoint )
    --THIS GIVES AN ERROR
    --format "SurroundsPoint %\n" ( splines[i].SurroundsPoint [0,0] )
	
	--SOLUTION, the point2 is defined inside the instance instead of passing it from maxscript
	format "SurroundsPoint %\n" ( splines[i].SurroundsPoint p )
	
    format "Spline % is self-intersecting: %\n" i (splines[i].SelfIntersects)
    for j=i+1 to splines.count where splines[i].IntersectsSpline splines[j] do
    (
      format "Spline % intersects spline %\n" i j
    )
  )
)

 Another doubt I have is if I should free those variables or maxscript does that automatically when they are inside a certain scope

Thanks again for your help

0 Likes
Message 6 of 6

MartinBeh
Advisor
Advisor

My expectation would be that both MAXScript and dotNet do their own garbage collection, so I don't think one has to "free" the variables. I might be wrong, though...

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes