-
Notifications
You must be signed in to change notification settings - Fork 8
Getting Started
Install by using either pip: TODOpip install pyvmf
or by adding the src
folder to your project directory.
Once in python:
from PyVMF import *
v = load_vmf("test.vmf")
v.visgroups.new_visgroup("abcd")
for solid in v.get_solids():
if solid.has_texture("tools/toolsnodraw"):
solid.move(0, 0, 64)
v.add_to_visgroup("abcd", solid)
v.export("test2.vmf")
This snippet moves every solid that has the nodraw
texture up 64 units and adds it to the abcd
visgroup. It's then exported as test2.vmf
from PyVMF import *
import math
v = load_vmf("test.vmf")
for solid in v.get_all_from_visgroup("exampleVisgroup"):
for i in range(150):
c = solid.copy()
c.move(384, 0, 0)
v.add_solids(c)
center = Vertex(0, 0, 0)
for i, solid in enumerate(v.get_solids()):
solid.move(128, 0, math.cos(i*3))
solid.rotate_y(center, i*3)
v.export("test2.vmf")
This snippet takes solids from the visgroup exampleVisgroup
, makes 150 copies, then rotates them all around the center of the map in a circle.
from PyVMF import *
v = load_vmf("test.vmf")
for solid in v.sort_by_attribute(v.get_solids(), "center.x"):
for disp_matrix in solid.get_displacement_sides(matrix_instead_of_side=True):
for x in range(disp_matrix.size):
for y in range(disp_matrix.size):
p = disp_matrix.get(x, y)
p.set((0, 0, 1), x*y)
v.export("test2.vmf")
This snippet takes all solids arranged from lowest solid center x position to highest, it then looks for any displacements. Once found it modifies it into a cool curved shape.
Almost everything can be accessed as class variables, v.versioninfo.mapversion
for example, but if the variable can't be found, even though it should exist, you can check the other
dictionary, which gathers all variables that haven't been coded in, this is especially important for Entities (because there are so many different ones), so to access it's variables, using e
as example of an entity: e.other["target_name"]
If you want information on how long the VMF export takes, you can enable VMF.info_in_console = True
, it provides a progress bar, and other such information.