SourceForge has been redesigned. Learn more.
Close

Scripts to load geometry files

2006-08-11
2013-04-22
  • John E. Nelson

    John E. Nelson - 2006-08-11

    Sean was nice enough to help me a few months back so I thought I would post an example script. My projects involve complex repetitive geometry of round and spherical objects so I wanted to write a program to produce the coordinates-objects automatically. To use the following, save as a text file with the name junk.tcl. Then Open a new mged database and Load the script. It will give you error messages that the objects cannot be killed because they do not exist, but no problem, the objects will be created. To adjust the location of objects go back and modify the text file and reload. Do not leave the file open in Notepad or a word processor, mged will crash. Don't doubleclick the text file as wish will choke on it. To "program" scripts you will have to learn tcl - but it is an easy language to learn. A few samples will probably get you started.  I am interested in using mged to visualize files created with tcl scripts. Also, I am interested in generating scripts to be used as input to CNC automilling and STL for stereolithograpy. Any folks that read these posts have similar interests?

    # Change MGED so that escape of characters is not needed

    set glob_compat_mode 0

    # remember to kill any objects before defining them again

    # set constant values

    set a 3
    set b 4
    set c 5
    set pi 3.141592

    # example procedure

    proc mult {varName {multiplier 2}} {
       upvar 1 $varName var
       set var [expr {$var * $multiplier}]
    }

    # polar to cartesian
    # x = r * cos( th )
    # y = r * sin( th )
    # 360 = 2*pi radians

    proc pcx {r th} {
       set x [expr $r*cos($th)]
    }

    proc pcy {r th} {
       set y [expr $r*sin($th)]
    }

    # example

    set k 0
    while {$k<30} {
        kill sph$k
        in sph$k sph [pcx 30 [expr 2*$pi*$k/30]] [pcy 30 [expr 2*$pi*$k/30]] $c $a
        incr k
    }

    # example

    kill base1
    in base1 rcc 0 0 0 0 0 [expr 3*$a] [expr 10*$a]

     
    • Jack Devanney

      Jack Devanney - 2006-09-08

      John's script shows how difficult or at least verbose Tcl is in doing the simplest arithmetic.
      For a big parametric model (eg a ship in
      which all the major particulars are variable)
      Tcl gets totally out of hand.
      I know cause I tried.
      My solution is to do the model in Perl,
      have the Perl script print out the tcl/brlcad
      file which is then sourced into mged.
      Indirect but works much better.

      KTF

      Jack

       
      • Sean Morrison

        Sean Morrison - 2008-05-08

        Jack,

        Interesting approach using Perl instead of Tcl, perhaps you could document what you've done on the BRL-CAD Wiki at http://brlcad.org/wiki/

        I added a similar tutorial where I used Sh instead of Tcl to create the SGI logo.

        Cheers!
        Sean

         

Log in to post a comment.