Centerpoint in simpel 2D symbol

Home Forums Problems and solutions in GDL Object design Centerpoint in simpel 2D symbol

Viewing 8 reply threads
  • Author
    Posts
    • #2977
      Anders Juul
      Participant

      Hi

      I have a simple rectangle, whits is set up to scale automatic after Pepersize.
      I would like that the symbol to scale from the center, and not from the corner.
      How do I do that?

      Here is my very simple GDL script and also se attached

      Best regards Anders / Denmark
      _

      _paperToModel = GLOB_SCALE / 1000
      bb = bb_mm * _paperToModel

      mul2 a, b
      add2 5, 5
      pen penAttribute_1

      line2 0*bb,0*bb,0*bb,3*bb
      line2 0*bb,3*bb,10*bb,3*bb
      line2 10*bb,3*bb,10*bb,0*bb
      line2 10*bb,0*bb,0*bb,0*bb

      _

      Attachments:
    • #2979
      David Maudlin
      Participant

      Anders:

      You will need to rewrite the code so the center of the rectangle is at the 0, 0 point. So the lower left will be two negative numbers (-5*bb, -1.5*bb), the upper right two positive numbers (5*bb, 1.5*bb). I think this is simpler than trying to use the Add2 command to adjust the center.

      David

      David Maudlin / Architect
      Washington, D.C.
      AC 22 - Mac OS

    • #2980
      Anders Juul
      Participant

      Thanks David

      But if the symbol is more complex like attached. Do i have to rewrite the code to?
      I created this symbol by select the drawings, and use “save selection as object”

      ___

      _paperToModel = GLOB_SCALE / 1000
      _size1_model = Str_mm * size1_mm * _paperToModel
      _size2_model = Str_mm * size2_mm * _paperToModel

      mul2 _size1_model , _size2_model
      add2 -6.838723289463, -2.084918350452
      pen penAttribute_1
      fill fillAttribute_1
      poly2_b{5} 15, 2, 0, 3, penAttribute_1, penAttribute_2,
      0, 0, 1, 0, 0, 1, 0,
      6.838723289463, 2.484918350452, 1,
      6.838723289463, 2.084918350452, 1,
      7.238723289463, 2.084918350452, 1,
      7.238723289463, 2.284918350453, 1,
      7.063723289463, 2.109918350452, 1,
      6.938723289463, 2.109918350452, 1,
      7.063723289463, 2.234918350452, 1,
      6.863723289463, 2.234918350452, 1,
      6.863723289463, 2.334918350452, 1,
      7.063723289463, 2.334918350452, 1,
      6.938723289463, 2.459918350452, 1,
      7.063723289463, 2.459918350452, 1,
      7.238723289463, 2.284918350453, 1,
      7.238723289463, 2.484918350452, 1,
      6.838723289463, 2.484918350452, 1
      pen penAttribute_3
      fill fillAttribute_1
      poly2_b{5} 10, 2, 0, 3, penAttribute_3, penAttribute_3,
      0, 0, 1, 0, 0, 1, 0,
      7.063723289463, 2.334918350452, 1,
      6.863723289463, 2.334918350452, 1,
      6.863723289463, 2.234918350452, 1,
      7.063723289463, 2.234918350452, 1,
      6.938723289463, 2.109918350452, 1,
      7.063723289463, 2.109918350452, 1,
      7.238723289463, 2.284918350453, 1,
      7.063723289463, 2.459918350452, 1,
      6.938723289463, 2.459918350452, 1,
      7.063723289463, 2.334918350452, 1
      _____

      Attachments:
    • #2982
      David Maudlin
      Participant

      Anders:

      You could solve this with the Add2 command (there is an Add2 command at line 5 of your script). The values (x, y) will need to be parametric depending on the desired size and the Mul2 values. It will take a bit of thinking and math to get the desired result. Going from a single drawn object to a parametric one is not simple, so this is why I prefer to code it.

      David

      David Maudlin / Architect
      Washington, D.C.
      AC 22 - Mac OS

    • #2983
      Péter Baksa
      Keymaster

      For all GDL objects, you can select which hotspot acts as origin for scaling. You can do it in the settings dialog preview pane. Simply add a hotspot in the place that you want to use as origo.

      If you need the default behaviour of your object being to scale from the origo, you have to do the transformations in the code, after mul2 move it half the new size to downwards and left.

      Another way to do it: before Save As, move the drawings center to the project origin, it will be saved relative to that position.

      Péter Baksa
      Library Platform, Software Engineer
      GRAPHISOFT SE

    • #2991
      Anders Juul
      Participant

      Thanks for your reply. I programed the symbol, and now the symbol scale from the center when I change the paper size 🙂

      One more question. How do I make al fill, so the symbol gets a colour : Se se attached

      / Anders

      _paperToModel = GLOB_SCALE / 1000
      bb = bb_mm * _paperToModel

      mul2 a, b
      add2 0, 0
      pen penAttribute_1
      line_property 0

      ! Firkant line
      line2 -500*bb,-500*bb,-500*bb,500*bb
      line2 -500*bb,500*bb,500*bb,500*bb
      line2 500*bb,500*bb,500*bb,-500*bb
      line2 500*bb,-500*bb,-500*bb,-500*bb
      ! pil line
      line2 -500*bb,0*bb,-50*bb,400*bb
      line2 -50*bb,400*bb,300*bb,400*bb
      line2 300*bb,400*bb,50*bb,150*bb
      line2 50*bb,150*bb, 400*bb,150*bb
      line2 400*bb,150*bb, 400*bb,-150*bb
      line2 400*bb,-150*bb, 50*bb,-150*bb
      line2 50*bb,-150*bb, 300*bb,-400*bb
      line2 300*bb,-400*bb, -50*bb,-400*bb
      line2 -50*bb,-400*bb, -500*bb,0*bb

      Attachments:
    • #2993
      David Maudlin
      Participant

      Anders:

      Since you have now defined all the points using the Line2 command, you can use these same points with one of the Poly2_ commands (which one you choose depends on the amount of control you want over the fill). The Poly2_ command can draw both the fill and its outline (look at the frame_fill options) so you will be able to remove the Line2 commands when done.

      David

      David Maudlin / Architect
      Washington, D.C.
      AC 22 - Mac OS

    • #2994
      Anders Juul
      Participant

      Hi David

      Can you give my an examble? My GDL skills is not the best 🙂

    • #2996
      David Maudlin
      Participant

      Anders:

      In the US library is an Object “Sign Handicap 20” which uses the Poly2_{2} command to draw the handicap symbol. It has hard coded x & y points rather than parametric ones like yours, but otherwise the concept is the same. See if you have this object or can search for it or a similar one to look at. Some information about General polygon can be found on this site 05 Basic 2D elements. Maybe the moderators can point to better examples.

      David

      David Maudlin / Architect
      Washington, D.C.
      AC 22 - Mac OS

Viewing 8 reply threads
  • The forum ‘Object design’ is closed to new topics and replies.