Showing posts with label Metasequoia scripts. Show all posts
Showing posts with label Metasequoia scripts. Show all posts

Wednesday, 9 March 2016

Metasequoia Script for Reference

RedRogueXIII has some Metasequoia Scripts on GitHub that can be studied to see how to create dialogs for your Metasequoia scripts.

https://github.com/RedRogueXIII/MetasequoiaScripts

The script shrinkwrap.py didn't work for me because for some reason the target object was not being set. I had to hardcode the target object. Since I had only one object in the target list I had to make sure I clicked on it for it to be set.

The script moves the selected vertices in a source object to the surface of the target object if a ray from the vertices in the chosen direction intersects a face of the target object.

The faces in the target object must be all triangles.

Wednesday, 1 July 2015

Metasequoia Script - Read uklogo.pak

uklogo.pak is the file which stores the title graphic for classic Tomb Raider games (TR1 to TR5).

uklogo.pak

In this post I will write a script that reads the uklogo.pak file.

Saturday, 12 July 2014

Metasequoia Script – Import MilkShape3D *.ms3d

Here is a script that imports a model from a MilkShape3D *.ms3d file.

The script uses Python 3 modules, syntax and objects so can only be used as is with Metasequoia 4.

MS3D model imported into Metasequoia 4


Monday, 30 June 2014

Metasequoia Script – Using Quaternions to Rotate Points

You can use a Python script in Metasequoia to demonstrate the quaternion sandwich product rotating a point.

I have set up a Metasequoia document as shown below.

Demonstate quatenion sandwich product in Metasequoia 4

Sunday, 22 June 2014

Metasequoia Script – Import one of your own modules

Sometimes a Metasequoia Python script may contain many lines of code.

To keep the script simple you can split the script into several smaller scripts.

For instance you could have all your function definitions in a script of their own.

To access those functions you would import the script containing your functions into your main script the same as we have been doing for Python’s inbuilt modules such as “math”.

The script you import must have a filename that is a valid Python identifier so cannot start with a number and use only letters or numbers or the underscore, ‘_’.

The script file must have the extension ".py".

The script you import must not have any executing code or only have executing code in an “if __name__== “__main__”:” block.

For Metasequoia 4 the script or scripts you import must be in the same folder with the main script.

If you use Metasequoia’s MQSystem classes in the script you import, in that script you must explicitly import the MQSystem module as follows or you will get errors.

import MQSystem

Saturday, 21 June 2014

Metasequoia Script – Display an OpenFile Dialog

This script shows how to display an OpenFile dialog in Metasequoia 4.

Metasequoia 3 doesn’t have the MQWidget classes so this script is only for Metasequoia 4.

You use an OpenFile dialog to get a filename (actually the full path to a file) for your script.

Once your script has a filename you could use standard Python code to read the file.

You could, for example, write a script to open a 3D file format that Metasequoia does not support.

Friday, 20 June 2014

Metasequoia Script – Script Template

See this post [link] for the basics of using Metasequoia’s Script Editor.

Here is a Python script you can use as a starting point for your scripts.


Monday, 16 June 2014

Metasequoia Script – Mikoto bdef bone influence

See this post [link] for the basics of scripting in Metasequoia.

In this post [link] I talk about how Mikoto assigns vertices to a bone using the geometry of the triangle created in Metasequoia for bdef meshes without using anchors.

To help visualise which vertices will be bound to a bone I wrote a script that shows the zone of influence of each bone.

The Metasequoia Python API doesn’t have routines to create Primitive objects so rather than create an object in code this script requires a Primitive to be created in Metasequoia which it can copy.

The Primitive object must be named capsule and have its properties set as shown in the screenshot below.

Create a capsule primitive with these settings


Saturday, 7 June 2014

Metasequoia Script–Lots of cubes

See this post [link] for the basics of using Metasequoia’s Script Editor.

I found an interesting script at this Japanese blog [link].


Friday, 6 June 2014

Metasequoia Script–Sierpinski Triangle Pyramid

See this post [link] for the basics of using Metasequoia’s Script Editor.

I found an interesting script at this Japanese blog [link].
 
# fractal generate

doc = MQSystem.getDocument()

num = doc.numObject
obj = doc.object[0]

# field

x = 100
y = 100
z = 100
rn = 4 # recursive number

# Primitive

p01 = MQSystem.newPoint(x/2,y,z/2)
p02 = MQSystem.newPoint(0,0,0)
p03 = MQSystem.newPoint(x,0,0)
p04 = MQSystem.newPoint(x,0,z)
p05 = MQSystem.newPoint(0,0,z)

# function fractal()

def fractal(number,p1,p2,p3,p4):

  if number == 1:
  
    #left
    
    v = []
    v.append( obj.addVertex(p1) )
    v.append( obj.addVertex(p2) )
    v.append( obj.addVertex(p3) )
    
    obj.addFace(v)
    
    #right
    
    v = []
    v.append( obj.addVertex(p1) )
    v.append( obj.addVertex(p3) )
    v.append( obj.addVertex(p4) )
    
    obj.addFace(v)
    
    # bottom
        
    v = []
    v.append( obj.addVertex(p4) )
    v.append( obj.addVertex(p3) )
    v.append( obj.addVertex(p2) )
    
    obj.addFace(v)
    
  else:
    p5 = MQSystem.newPoint((p1.x + p2.x)/2, (p1.y + p2.y)/2, (p1.z + p2.z)/2)
    p6 = MQSystem.newPoint((p2.x + p3.x)/2, (p2.y + p3.y)/2, (p2.z + p3.z)/2)
    p7 = MQSystem.newPoint((p3.x + p1.x)/2, (p3.y + p1.y)/2, (p3.z + p1.z)/2)
    p8 = MQSystem.newPoint((p3.x + p4.x)/2, (p3.y + p4.y)/2, (p3.z + p4.z)/2)
    p9 = MQSystem.newPoint((p4.x + p1.x)/2, (p4.y + p1.y)/2, (p4.z + p1.z)/2)
    p10 = MQSystem.newPoint((p4.x + p2.x)/2, (p4.y + p2.y)/2, (p4.z + p2.z)/2)
        
    fractal(number-1,p1,p5,p7,p9)
    fractal(number-1,p5,p2,p6,p10)
    fractal(number-1,p7,p6,p3,p8)
    fractal(number-1,p9,p10,p8,p4)
    fractal(number-1,p7,p8,p10,p6)
     
# endfunction fractal()

#main()

fractal(rn,p01,p02,p03,p04)
fractal(rn,p01,p04,p05,p02)

Make sure you have an empty Scene in Metasequoia by clicking File>New then open the Script Editor and paste the code into the upper input pane of the editor.

Paste the code into the Script Editor's input window

Press F5 or Script>Run to execute the script and create the object.

Execute the script to create the object




Tuesday, 27 May 2014

Metasequoia Script – integer vertex coordinates

The registered version of Metasequoia allows scripting in the Python language.

This article will demonstrate a script to move all vertices (also known as points) in an object to integer coordinates.

An integer is a whole number like 1, 2, 3, 40, 75 etc.

A trial license for Metasequoia 4 is easy to obtain and unlocks all features for a limited time including the Script Editor. [link]