1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Script prerelease - CoG-Point Update V03

Discussion in 'Alibre Script' started by idslk, Jul 12, 2020.

  1. idslk

    idslk Alibre Super User

    Edit: Update to V03
    renames the original point names in EE and adds a date to the CoG point to show when it was created

    Hello colleagues,
    this script uses the physical properties to generate 3 variables in the Equation Editor and an 3D-point in the design to represent the center of gravity for the part or assembly.
    The script was only pretested on systems running on millimeters!!!
    The CoG-position is only calculated at the runtime of the script!!!
    Changing the design won't automatically update the values!!!
    The script can be run again to change the values to the new design.
    The appended part-file should contain also the script itself.
    In the part are two supressed features.
    You can run the script and you will generate the "CoG_Temporary!" point in the design.
    If you now unsuppress one or two of the suppressed features and run the script again, you will see that the CoG-Point will update.
    You can use the "CoG_Temporary!" as an reference for your further design, but be aware of the static character!
    As there is no automatic included, you have to run the script each time you change the design, otherwise the "CoG_Temporary!" (and the regarding EE-Values) will represent the wrong position.
    It would be nice if someone could check the behaviour of the script on an system with different native units (inches or whatever is possible) and give me some feedback.
    "AS Ever": USE ON YOUR OWN RISK!
    upload_2020-7-12_20-21-14.png
    Regards
    Stefan
     

    Attached Files:

    Last edited: Jul 31, 2020
  2. Lew_Merrick

    Lew_Merrick Alibre Super User

    Hi Stefan -- I will play with it and (almost certainly) get back to you. -- Lew
     
  3. Lew_Merrick

    Lew_Merrick Alibre Super User

    Hi Stefan -- As somebody who predominately works in inches I note "strange things" for anything not defined in millimetres as shown in the attached (Package) file. -- Lew
     

    Attached Files:

  4. idslk

    idslk Alibre Super User

    Hello Lew,
    nice that you're testing the script. First to mention, it does not help to sent me a package, because my system runs on millimeters and so if i open the package incl. script, it will run also in millimeters...It makes more sense to me, that you describe what happens if you run the script without any modification! I assume the Cog_Real coordinates can be a pysical property calculation, but i'm not shure.
    If you take a part (one like a cube 2*2*2 inches) and run the script and post the script calculated values and the values of the pysical properties that i can compare them.
    Thanks in advance
    Stefan
     
    Last edited: Jul 12, 2020
  5. idslk

    idslk Alibre Super User

    Hello Lew,
    i've made a change assuming a system in inches need a conversation factor from millimeters to inches (25.4 mm = 1 inch)
    Done the script change in your part appended...please run the script again and report the reaction,
    Thanks in advance
    Regards
    Stefan
     

    Attached Files:

  6. Lew_Merrick

    Lew_Merrick Alibre Super User

    Hi Stefan -- I made my own "update" that I hope meets with your approval. I am, at best, a kludge hacker rather than a real programmer (says somebody who spent several years working with Arne Henden and knows what a real programmer delivers as code). [Arne wrote self-modifying code for space probes. When I write self-modifying code it generates FATAL CRASH as the notification.] -- Lew
     

    Attached Files:

  7. idslk

    idslk Alibre Super User

    Hi Lew,
    to be honest: "Please do not publish your own update". You don't need to write "self-modifying code" to make something to disfunction.
    It sould be also better to not use your own "code" in your projects...
    The idea was to make the script running on different "unit systems" and not that what you've done...sorry.
    It was simply "run the script on a machine with an other native unit system than millimeter and report the results" nothing more...
    Regards
    Stefan
     
  8. Lew_Merrick

    Lew_Merrick Alibre Super User

    Hi Stefan -- All I did was to add "unit declaration" along with an "adjustment factor" that converts the default centimetres into a "user selected" unit set. Quick, easy, and stupidly simple. It was a "quick fix" for my situation, nothing more. -- Lew [Hey, I did not add "Furlongs" as units.]
     
  9. idslk

    idslk Alibre Super User

    Hi Lew,
    your
    does nothing.
    Your name change for the point kills the update of parameters for the point and creates instead a new point with the same name but own (and so maby different) coordintes. As you said it's only for your situation...
    Over all: not helpful! Sorry
    Regards
    Stefan
     
  10. Lew_Merrick

    Lew_Merrick Alibre Super User

    Hi Stefan -- I made "changes" that got things working for me -- and would be far from "disappointed" should an "update" be made available that allowed for any "user defined units" to be allowed. Mind you (and this is a really antique tale) I had to convert gravities into Furlongs/Fortnight² as part of an "entrance exam" to join a NASA development team. -- Lew
     
  11. NateLiqGrav

    NateLiqGrav Alibre Super User

    Stefan,
    Here is a function I made a while back for my own script for setting the script's units to the file's Display Units. Feet and inches, feet, and meters are not an option in AlibreScript but are for Display Units - so the error is handled by alerting the user and setting it to the next "best" option. Feel free to use or modify it for your own needs.
    Code:
    def is_assembly():
        try:
            CurrentAssembly()
            return True
        except:
            return False
    
    def SetUnitsToDisplayUnits():
        try:
            if is_assembly():
                Units.Current = CurrentAssembly().DisplayUnits()
            else:
                Units.Current = CurrentPart().DisplayUnits()
        except Exception, e:
            if 'AD_FEET_INCHES' in str(e):
                print('Feet and Inches not supported for AlibreScript Units so defaulting to Inches')
                Units.Current = UnitTypes.Inches
            elif 'AD_FEET' in str(e):
                print('Feet not supported for AlibreScript Units so defaulting to Inches')
                Units.Current = UnitTypes.Inches
            elif 'AD_METERS' in str(e):
                print('Meters not supported for AlibreScript Units so defaulting to Millimeters')
                Units.Current = UnitTypes.Millimeters
            else:
                print(str(e))
        return
       
    SetUnitsToDisplayUnits()
    print('Script Units set to ' + str(Units.Current))
     
  12. idslk

    idslk Alibre Super User

    Hello Nate,

    it's kind that you would provide the function to me, but that is not the thing i need in this case. It would be very helpful if you download the appended part in this post, let the script run twice and post a screenshot of the console output and please without any changes.
    It seems that there is one parameter with two values (inch and millimeter) which drives the physical parameter calculations inside Alibre. In addition it has to be taken in account that the values are in E-notation. So no matter what skript or display units i am using, on my mashine it calculates always in millimeters.
    Here is the result on my PC running the script in CoG_simple_v2.AD_PRT twice:
    upload_2020-7-16_17-52-49.png

    TIA
    Stefan
     

    Attached Files:

  13. NateLiqGrav

    NateLiqGrav Alibre Super User

    upload_2020-7-16_13-56-38.png

    Ok yes, AlibreScripts Units only apply to AlibreScript and not the API. The API uses Model Units.
    upload_2020-7-16_14-3-9.png
     
  14. idslk

    idslk Alibre Super User

    Thank you Nate,

    now it should be easy to react on different units...i read that in the past, but couldn't remember it...maybe it was stored under 3D Systems, Inc in my mind:D
    Do you think that "workspaces imported from other sources" are STP,SAT and the other import formats?
    Anyway, can you please do another thing for me? Can you check if the script CoG-point is at the same point as the physical properties calculation states on your system?

    Regards
    Stefan
     
  15. DavidJ

    DavidJ Alibre Super User Staff Member

    Stefan, yes - imported files impose their own units as model units. Native Alibre files always use cm (unless you take special measures to force otherwise).
     
  16. idslk

    idslk Alibre Super User

    Hello Colleagues,

    in the start post is an update to V03 to the CoG script available.
    Now it doesn't adds new variables to EE, instead it renames the original ones
    It adds the CoG with date and time to see when it was created and to decide if it's time to run the script again...;)
    upload_2020-7-31_17-42-40.png

    Regards
    Stefan
     

Share This Page