Jump to content

Dieter @ DWorks

  • Posts

  • Joined

  • Last visited

Posts posted by Dieter @ DWorks

  1. You can test without VW if you mock the vs module. It's easy and straightforward to do. Though how easy it is depends on what exactly you are testing....

    As for testing your script from within VW, take a look at DLibrary, which did this.

    • Like 1
  2. 11 hours ago, ahedley said:

    Most of my experimentation has been developing plugin objects, I want to broaden to tool objects.


    Tools aren't objects. Tools are used to generate objects. For example, the rectangle tool will let you create a rectangle in different ways. The rectangle object is the result. The creation of it is what the tool does, and those two have no connection at all. An object should not know how it is created.

  3. 3 hours ago, twk said:


    This is using the vs.GetRField call and not the P<parmaname> method.



    Aha, so that could be the real problem! So P.... is cutting it off, and thus it's better to use GetRField for text fields... Hmmm. Need to test this and then add it as improvement to DLibrary!

  4. 11 hours ago, MaxStudio said:

     That being said, I find it much easier to comprehend looking at small pieces of code rather than a monster.


    A monster? That was a minimal version. You'll have to think differently in Python then you did in VectorScript. Working OOP, you can split things up in very small pieces, and then let them work together. Every piece has it's own responsibility, and this makes your code more clear and better to read. You only have to read the main flow, and if you are interested in the details, you can look deeper. For example, if you look at the run in it, you can read was is going on, without needing to know the details, you know what will be drawn, not how. If you want to know how, you can look deeper.

    • Like 1
  5. Hi,

    for those interested, DLibrary is an open-source Python library to create VW plugins. I have moved the repo to github (still have to transfer the issues), as it has better collaboration support and a far better wiki system. https://github.com/dietergeerts/dlibrary. The main benefits of the library is that you can program OOP, plugin setup is a breeze, so are custom dialogs. Not all is already in there, but everyone is welcome to contribute.

    Just wanted to post this so that more people know of it's existence, and that it's still alive (and kicking).

    • Like 4
  6. 17 hours ago, ahedley said:

    Thanks Dieter for the suggestion.

    pt is still trapped in the callback function.

    user_point = None creates the locus at 0,0 even before you have an oppportunity to select your user point.

    Even if you make user_point a global variable within the callback function which should theoretically change user_point = None it still does not work.

    I see now, it's stated in the docs that script execution will not be blocked (like most other functions do): http://developer.vectorworks.net/index.php/VS:GetPt

    That means that you have to make sure that you first call that function, and that the callback is actually your main function to execute with everything in it.

  7. You could use http://developer.vectorworks.net/index.php/VS:ValidAngStr, which converst a string into a float angle. The same goes for distances in python, you can't use string, but they can be converted. I put this into dlibrary, so we can use strings like '5m', have a look, you should do something similar for angles: https://bitbucket.org/dieterdworks/vw-dlibrary/src/ac2110e58529cb69cede4a04a94219fc38634fd0/dlibrary/document.py?at=master&fileviewer=file-view-default


  8. Some tips:

    - A file is a module, which is a unit with stuff that work together. You'll never split it up. Things that belong together in a module should stay together.

    - Never use global variables, there are always better ways. Functions should almost always stand on their own, unless it's a function inside a class that needs the 'state' of the class.

    - use good names for your vars, so it's clear what they are, if you revisit your code years later, you want to know how it works, good naming will help with that.

    - use oop, so that the code is more clear and each thing is self-contained. It will make your code better, readable, etc....

    Here is a better version of your code (at the top of my head, did not test it, depending on what you are trying to achieve, this could be made far better, some imports are missing, i'm not using my standard IDE right now.)

    import vs
    class Shape(object, metaclass=ABCMeta):
        def __init__(self, origin: tuple, width: float, height: float):
            :type origin: (float, float)
            self.__origin = {x: origin[0], y: origin[1]}
            self.__width = width
            self.__height = height
        def origin(self) -> dict:
            return self.__origin
        def width(self) -> float:
            return self.__width
        def height(self) -> float:
            return self.__height
        def draw(self):
    class Rectangle(Shape):
        def draw(self):
            vs.Rect(self.origin.x, self.origin.y, self.origin.x + self.width, self.origin.y + self.height)
    class Oval(Shape):
        def draw(self):
            vs.Oval(self.origin.x, self.origin.y, self.origin.x + self.width, self.origin.y + self.height)
    def run():
        plugin_length = vs.PLineLength
        plugin_height = vs.PBoxWidth
        x = 0
        y = 0 - plugin_height / 2
        if plugin_length == 6:
            vs.AlrtDialog('Hello world.')
        my_shape_class = Rectangle if plugin_length < 6 else Oval
        my_shape = my_shape_class((x, y), plugin_length, plugin_height)
    # This should not be needed here, you can call it in your plugin file itself.


    • Like 1
  9. 8 hours ago, twk said:

    @Dieter @ DWorksgreat share!.. I may have opened my mouth too soon about contributing, seeing the VW2017 has just been released, our office is gearing up for the release here in NZ, and I'll be setting up the new templates etc.

    What I had wanted to share though were mainly methods I had done for the Polygon methods, and some attributes that I've setup in our own library that could be used in the DLibrary opensource (attributes were open/closed,clockwise,vertexXY,vertexType etc.

    I tried pulling a fork using PyCharm but I'm having trouble setting up the bitbucket plugin for PyCharm. Will try again and post back.


    Just share when you're ready.

    You don't need any plugin for PyCharm, version control is already baked in: https://www.jetbrains.com/help/pycharm/2016.1/version-control-with-pycharm.html.
    Just check out the project, open it in PyCharm, and it should detect all, probably asking you what to do. Then you can just use the version control menu from then on.

  10. yes, and so many others, level bounding for symbols, etc.... I was really surprised to see all these things they didn't mention, VW is on a good path again. Isn't there a list with ALL improvements and new things?

    I really hope for a continuous release of new features to know these improvements instead of one big one each year. (or one big one for the BIG sales stuff, and updates for all those smaller things)

  11. I have the Surface Pro 4 i7 16GB RAM 256 GB SSD, and I've tested VW2016 on it. It works great, though some renderings didn't work. I guess for all work, except rendering, this machine will do. The main reason I bought this, is because I wanted to use VW on the go and to show VW stuff to clients, and I was totally happy with my first Pro model. The pen is amazing! I would not recommend any such device as the main VW machine though. Still prefer to assemble my own setup for that.

    • Like 1
  12. On 9/15/2016 at 2:01 AM, twk said:

    Hi Dieter, are you still planning on an opensource-type library? As I would like to start contributing for the next vw2017 release. I feel a bit more comfortable now with Git and OOP.


    DLibrary is already opensource and anyone can contribute. Some parts can really be improved a lot. For the new VW2017 release, I have rewritten the Vectorworks module, so plugins can be more easily created with it, by using configuration. I'll also add examples etc... When contributing, just keep in mind that in one main version, no breaking changes are allowed, and between versions, try to keep them to a minimum.

    So please do contribute on anything that's needed. And ask away if something isn't clear so we can improve the docs etc...

  13. On 06/09/2016 at 7:15 PM, zoomer said:

    I second the signature move to the top.


    Currently it is quite hard for me to recognize where the content of a post is,
    where one post begins/ends and where the next post starts.

    So true, as this new layout may seem nice and modern at first, it's really terrible. The design is really bad, because you can't see the contexts well enough, which makes it hard to navigate and use the site. Also more color would be nice, maybe add some variable in the styling to change that color every year to reflect the new VW color?

  • Create New...