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



Notation Wizard

Allows the user to select parameters for 2D(Fixed) and 3D(Active) Text notation in View Mode (3D Editor) and allows script to be embedded in drawing file, or will eventually.

Script Contents (Lang: lua)

-- --------------------------------------------------------------------
-- SETUP AND DISPLAY WIZARD INTERFACE FOR SCRIPT.
-- --------------------------------------------------------------------

cmd("wizard.load NotationWizard.wzd")

-- Assign all OnClick events before 'wizard.show'.

set("wizard.Page1.FixedText.OnClick Text2DVisible")
set("wizard.Page1.ActiveText.OnClick Text3DVisible")

-- Define all OnClick callback functions before 'wizard.show'.

function Text2DVisible (page, item)
    set("wizard.Page2.Visible", true)
    set("wizard.Page3.Visible", false)
    if item ~= "FixedText" then
       set("wizard.Page1.FixedText.Checked", true)
       set("wizard.Page2.Active", true)
    end
end

function Text3DVisible(page, item)
    set("wizard.Page3.Visible", true)
    set("wizard.Page2.Visible", false)

    if item ~= "ActiveText" then
       set("wizard.Page1.ActiveText.Checked", true)
       set("wizard.Page3.Active", true)
    end
end

-- Display the wizard dialog and interact with user.
cmd("wizard.show")

-- Bring ECOTECT to the front if it is not already.
cmd("app.activate")

-- --------------------------------------------------------------------
-- SOME COMMON ATTRIBUTES...
-- --------------------------------------------------------------------

    -- color code:
    Colors = { 16711680, 6711022, 3398912, 16776960 }

    -- text orientation code:
    Alignment = {  0, 2, 6, 8, 24  }
      --TopLeft = 0
      --Right = 2
      --Center = 6
      --Bottom = 8
      --Baseline = 24

    -- pen width code:
    Pen = {  .25, .5, .75, 1, 2, 3, 4, 5  }

-- --------------------------------------------------------------------
-- GENERATE 2D TEXT...
-- --------------------------------------------------------------------

-- Check if user selected 'FixedText'.
if get("wizard.Page1.FixedText.Checked") > 0 then

    -- Store wizard values as local variables.

    TextCaption = tonumber(get("wizard.Page2.EditText.Text"))
    PenColorIndex = tonumber(get("wizard.Page2.EditPenColor.Selected"))
    PenWidthIndex = tonumber(get("wizard.Page2.EditPenWidth.Selected"))
    ArrowSize = tonumber(get("wizard.Page2.EditArrowSize.Text"))
    SelectObjects = tonumber(get("wizard.Page2.SelectObjects.Text"))
    TextLocationX = tonumber(get("wizard.Page2.EditTextLocationX.Text"))
    TextLocationY = tonumber(get("wizard.Page2.EditTextLocationY.Text"))
    FontSize = tonumber(get("wizard.Page2.FontSize.Text"))
    TextAlignmentIndex = tonumber(get("wizard.Page2.TextAlignment.Selected"))

    TextAlignment = Alignment[TextAlignmentIndex]
    PenColor = Colors[PenColorIndex]
    PenWidth = Pen[PenWidthIndex]
    objects = { SelectObjects }

    -- Clear the current selection set.
    cmd("select.none");

    function OnRedraw (full)

        for i = 1, getn(objects) do

            x, y, z = get("object.center", objects[i])
           set("view.align", TextAlignment)
           cmd("view.draw.text2d", TextLocationX, TextLocationY, FontSize, TextCaption)
           cmd("view.draw.move2d", TextLocationX, TextLocationY)
           cmd("view.draw.arrowto", x, y, z, ArrowSize)

        end

     end

     OnRedraw(true)

   --PRINT 2D TEXT RESULTS FOR SCRIPT EMBEDDED AUTORUN:

     line = ""
     line = line .. "\n"
     line = line .. "function OnRedraw(full)\n"
     line = line .. "\n"
     line = line .. "\tfor i = 1, getn(objects) do\n"
     line = line .. "\t\tx, y, z = get(\"object.center\", objects[i])\n"
     line = line .. "\t\tset(\"view.align\", \" TextAlignment)\n"
     line = line .. "\t\tcmd(\"view.draw.text2d\", TextLocationX, TextLocationY, FontSize, \" .. TextCaption .. \")\n"
     line = line .. "\t\tcmd(\"view.draw.move2d\", TextLocationX, TextLocationY)\n"
     line = line .. "\t\tcmd(\"view.draw.arrowto\", x, y, z, ArrowSize)\n"
     line = line .. "\n"
     line = line .. "\tend\n"
     line = line .. "\n"
     line = line .. "end\n"

     print(line)

end

-- --------------------------------------------------------------------
-- GENERATE 3D TEXT...
-- --------------------------------------------------------------------

-- Check if user selected 'FixedText'.
if get("wizard.Page1.ActiveText.Checked") > 0 then

    -- Store wizard values as local variables.

    TextCaption = tonumber(get("wizard.Page3.EditText.Text"))
    PenColorIndex = tonumber(get("wizard.Page3.EditPenColor.Selected"))
    PenWidthIndex = tonumber(get("wizard.Page3.EditPenWidth.Selected"))
    ArrowSize = tonumber(get("wizard.Page3.EditArrowSize.Text"))
    SelectObjects = tonumber(get("wizard.Page3.SelectObjects.Text"))
    TextLocationX = tonumber(get("wizard.Page3.EditTextLocationX.Text"))
    TextLocationY = tonumber(get("wizard.Page3.EditTextLocationY.Text"))
    TextLocationZ = tonumber(get("wizard.Page3.EditTextLocationZ.Text"))
    FontSize = tonumber(get("wizard.Page3.FontSize.Text"))
    TextAlignmentIndex = tonumber(get("wizard.Page3.TextAlignment.Selected"))

    TextAlignment = Alignment[TextAlignmentIndex]
    PenColor = Colors[PenColorIndex]
    PenWidth = Pen[PenWidthIndex]
    objects = { SelectObjects }

    -- Clear the current selection set.
    cmd("select.none");

    function OnRedraw(full)

             for i = 1, getn(objects) do

                 x, y, z = get("object.center", objects[i])
                 set("view.align", TextAlignment)
                 cmd("view.draw.text", TextLocationX, TextLocationY, TextLocationZ, FontSize, TextCaption)
                 cmd("view.draw.moveto", TextLocationX, TextLocationY, TextLocationZ)
                 set("view.pen", Colors, PenWidth)
                 cmd("view.draw.arrowto", x, y, z, ArrowSize)

                 --PRINT 3D TEXT RESULTS FOR SCRIPT EMBEDDED AUTORUN:

                 line = ""
                 line = line .. "\n"
                 line = line .. "function OnRedraw(full)\n"
                 line = line .. "\n"
                 line = line .. "\tfor i = 1, getn(objects) do\n"
                 line = line .. "\t\tx, y, z = get(\"object.center\", objects[i])\n"
                 line = line .. "\t\tcmd(\"view.draw.text\", TextLocationX, TextLocationY, TextLocationZ, FontSize, \" .. TextCaption .. \")\n"
                 line = line .. "\t\tcmd(\"view.draw.moveto\", TextLocationX, TextLocationY, TextLocationZ)\n"
                 line = line .. "\t\tcmd(\"view.draw.arrowto\", x, y, z, ArrowSize)\n"
                 line = line .. "\n"
                 line = line .. "\tend\n"
                 line = line .. "\n"
                 line = line .. "end\n"

                 print(line)

             end

    end

    OnRedraw(true)

end



-- --------------------------------------------------------------------
-- TEST PRINT RESULTS...
-- --------------------------------------------------------------------

  --TEST PRINT ATTRIBUTES:
  --print(TextCaption)
  --print(PenColor)
  --print(PenWidth)
  --print(ArrowSize)
  --print(SelectObjects)
  --print(TextLocationX)
  --print(TextLocationY)
  --print(FontSize)
  --print(TextAlignment)

AttachmentSize
NotationWizard.zip175.19 KB

HOW WOULD YOU RATE THIS SCRIPT ?

No votes yet


Navigation

User login

Translate Site To: