Archive site for Autodesk Ecotect Analysis educational resources, notes and tutorials



Surface Creation Wizard

This tool takes two lines as inputs and creates a triangulated surface between them

Script Contents (Lang: lua)

cmd("wizard.load SurfaceWizard.wzd")

cmd("wizard.show")

pointCollector = {}

divisions = get("wizard.Page1.VertCount.Text")
Ydivs = get("wizard.Page1.HorizCount.Text")
nodes1 = {}
nodes2 = {}

function getDistance(pt1, pt2)
    xD = pt2[1] - pt1[1]
    yD = pt2[2] - pt1[2]
    zD = pt2[3] - pt1[3]
    value = sqrt(xD^2 + yD^2 + zD^2)
    return value
end


function createDivPoints(pt1, pt2)

    xD = pt2[1] - pt1[1]
    yD = pt2[2] - pt1[2]
    zD = pt2[3] - pt1[3]

    ptLines = {}
    for i = 0, divisions do
        temp = {}
        temp[1] = pt1[1]+(i*(xD/divisions))
        temp[2] = pt1[2]+(i*(yD/divisions))
        temp[3] = pt1[3]+(i*(zD/divisions))
        ptLines[i] = temp

    end
    pointCollector[getn(pointCollector)+1] = ptLines
end
-----------------------------------------------------------------------------------------------------------
--gets selected curve indicies
numObjects = get("selection.count")  
if (numObjects == 2) then
    curve1 = get("selection.next")
    numNodes1 = get("object.nodes", curve1)
    for i = 0, numNodes1 do 
        x, y, z = get("object.node.position", curve1, i)
        temp={x,y,z}
        nodes1[i]=temp
    end

    curve2 = get("selection.next")
    numNodes2 = get("object.nodes", curve2) 
    for i = 0, numNodes2 do 
        x, y, z = get("object.node.position", curve2, i)  
        temp={x,y,z}
        nodes2[i]=temp
    end
else
        cmd("app.alert", "Warning: You must have exactly two (2) line objects selected for this wizard to work.") 
end

cmd("select.none")
cmd("view.redraw")

-----------------------------------------------------------------------------------------------------------
if Ydivs < getn(nodes1) then
    Ydivs = getn(nodes1)
end
if Ydivs < getn(nodes2) then
    Ydivs = getn(nodes2)
end
-----------------------------------------------------------------------------------------------------------
while getn(nodes1) < Ydivs do
    biggestD = 0
    bi = -1
    for i = 0, getn(nodes1)-2 do
        tD = getDistance(nodes1[i],nodes1[i+1])
        if tD > biggestD then
        biggestD = tD
        bi = i
        end
    end
    x_D = nodes1[bi+1][1] - nodes1[bi][1]
    y_D = nodes1[bi+1][2] - nodes1[bi][2]
    z_D = nodes1[bi+1][3] - nodes1[bi][3]
    newN = {nodes1[bi][1]+x_D/2,nodes1[bi][2]+y_D/2,nodes1[bi][3]+z_D/2}
    v = getn(nodes1)
    for i = v , bi+1,-1 do
        nodes1[i+1] = nodes1[i]
    end
    nodes1[bi+1] = newN
end


while getn(nodes2) < Ydivs do
    biggestD = 0
    bi = -1
    for i = 0, getn(nodes2)-2 do
        tD = getDistance(nodes2[i],nodes2[i+1])
        if tD > biggestD then
        biggestD = tD
        bi = i
        end
    end
    x_D = nodes2[bi+1][1] - nodes2[bi][1]
    y_D = nodes2[bi+1][2] - nodes2[bi][2]
    z_D = nodes2[bi+1][3] - nodes2[bi][3]
    newN = {nodes2[bi][1]+x_D/2,nodes2[bi][2]+y_D/2,nodes2[bi][3]+z_D/2}

    v = getn(nodes2)
    for i = v , bi+1,-1 do
        nodes2[i+1] = nodes2[i]
    end
    nodes2[bi+1] = newN
end
-----------------------------------------------------------------------------------------------------------
for i = 0getn(nodes1)-1 do
    createDivPoints(nodes1[i],nodes2[i])
end 
-----------------------------------------------------------------------------------------------------------
reflector = get("wizard.Page2.CheckBoxReflector.Checked")
shaded = get("wizard.Page2.CheckBoxShaded.Checked")
newZone = get("wizard.Page2.CheckBoxNewZone.Checked")
elementType = get("wizard.Page2.ComboBoxElementType.Text") 
obj_count = 0

if (newZone == true) then
    index = add("zone", "Facets")
end

cmd("app.busy.open Calculating surfaces - please wait...")
for i = 0, divisions-1  do
        set("app.progress", (i/divisions)*100)
    for j = 1, getn(pointCollector)-1 do
            cmd("app.busy.update", format("%d objects created", obj_count))
        tri = add("object",elementType,"plane",true)
            add("node", tri, 0, pointCollector[j][i][1], pointCollector[j][i][2], pointCollector[j][i][3])
            add("node", tri, 1, pointCollector[j+1][i][1], pointCollector[j+1][i][2], pointCollector[j+1][i][3])
            add("node", tri, 2, pointCollector[j][i+1][1], pointCollector[j][i+1][2], pointCollector[j][i+1][3])
            add("node", tri, 3, pointCollector[j][i][1], pointCollector[j][i][2], pointCollector[j][i][3])
            cmd("object.done")
            if (reflector == true) then
                set("object.tag", tri, 256, true)
            end

            if (shaded == true) then
                set("object.tag", tri, 32, true)
            end

            --cmd("view.redraw")
        tri = add("object",elementType,"plane",true)
            add("node", tri, 0, pointCollector[j+1][i+1][1], pointCollector[j+1][i+1][2], pointCollector[j+1][i+1][3])
            add("node", tri, 1, pointCollector[j][i+1][1], pointCollector[j][i+1][2], pointCollector[j][i+1][3])
            add("node", tri, 2, pointCollector[j+1][i][1], pointCollector[j+1][i][2], pointCollector[j+1][i][3])
            add("node", tri, 3, pointCollector[j+1][i+1][1], pointCollector[j+1][i+1][2], pointCollector[j+1][i+1][3])
            cmd("object.done")
            if (reflector == true) then
                set("object.tag", tri, 256, true)
            end

            if (shaded == true) then
                set("object.tag", tri, 32, true)
            end

            --cmd("view.redraw")
    obj_count = obj_count + 2
    end
end
cmd("selection.group")
cmd("app.busy.close")
cmd("view.redraw")

AttachmentSize
SurfaceWizard.zip27.34 KB

HOW WOULD YOU RATE THIS SCRIPT ?

Average: 3 (1 vote)


Navigation

User login

Translate Site To: