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



Script example 06

DrawOn3dView.scr

This script demonstrates how you can not only draw lines on the current 3D view, but also overlay textual infomation and use arrows to point out specific features.

Note the use of arrows to point from a 2D text position at the top-right of the canvas to a 3D point within the model. If you rotate the 3d view and re-run the script, you can see that the 3D points move to maintain the exact model coordinates.

Script Contents (Lang: lua)

-- ------------------------------------------------
-- DRAWING ON THE CURRENT VIEW:
-- This script demonstrates how you can draw within
-- the current view as well as overlaying text and 
-- indicator arrows.
-- ------------------------------------------------

pt = {}
pt[1] = { 8000, 1000, 500 }
pt[2] = { 5000, 4000, 1000 }
pt[3] = { 1000, 4000, 1500 }
pt[4] = { 1000, 1000, 2000 }
lineSpace = 20;

-- Bring ECOTECT to the front.
cmd("app.activate")

-- Clear the view.
cmd("view.redraw")

-- Set default font to 8pt Arial.
set("view.font", 8, "Arial")

-- Set pen to light blue and 2 pixels wide.
set("view.pen 0xFF8888", 2)

-- Move to start point.
cmd("view.draw.moveto", 1000, 1000, 0)

-- Draw 4 points.
for i = 1,4 do
  if i < 4 then
    cmd("view.draw.lineto", 
      pt[i][1], pt[i][2], pt[i][3]
      )
  else
    cmd("view.draw.arrowto", 
      pt[i][1], pt[i][2], pt[i][3], 3.0
      )
  end
end

-- Align text to baseline.
set("view.align", 24)
cmd("view.draw.text", pt[2][1], pt[2][2], pt[2][3], 11, 
  "<i>This is</i> <b>some <r>formatted</r></b> text"
  )

-- Align text to Centre & Bottom (8+6=14).
set("view.align", 14)
cmd("view.draw.text", pt[3][1], pt[3][2], pt[3][3], 11, 
  "This is some plain text"
  )

-- Right align text.
set("view.align", 2)

-- Get dimensions of drawing canvas.
width, height = get("view.size")

-- Set pen to red and 1 pixel wide.
set("view.pen 0x0000FF", 1)

-- Set default font to 10pt verdana.
set("view.font", 10, "Verdana")

textLines = {}
textLines[1] = "This is the first node."
textLines[2] = "This is the second node."
textLines[3] = "This is the third node."
textLines[4] = "This is the fourth node."

-- Draw an arrow from a 2D text position to a 3D 
-- model position. Try rotating the view to see 
-- that the 3D positions follow the actual model 
-- coordinates whilst the 2D points remain static.
for i = 1,4 do

  cmd("view.draw.text2d", 
    width-10, -10+(i*lineSpace), 
    15, textLines[5-i]
    )

  cmd("view.draw.move2", 
    width-215, -2+(i*lineSpace)
    )

  cmd("view.draw.arrow", 
    pt[5-i][1], pt[5-i][2], 
    pt[5-i][3], 3.0
    )

  pause(800)

end

-- Reset to default font.
set("view.font", 8, "Arial")

HOW WOULD YOU RATE THIS SCRIPT ?

No votes yet


Navigation

User login

Translate Site To: