hexagon logo

Does someone have python-Adams examples

Hey guys,
 
I am looking into using python scripts in Adams instead of the command language.
So far I have found 2 examples scripts in the 'adamspy' folder and the help function also provides some examples and classes definitions. However, i feel like i am missing examples to problem solve things i encounter. Does anyone know where i could find more examples?
 
As an problem example; i got this simple script that creates 2 markers, and should parametrize one marker to the other marker. However, the location of the marker isn't updated. Do i need to call an mod.update() or something?
 
python script
marker not updated
Thanks in Advance!
  • Hello Niels,
     
    Please find a link to the webinar regarding Adams-Python Interface which is available on SimCompanion:
     
    I hope it will be valuable for you as well.
     
    Best,
    Krystian
     
  • Hi Niels,
     
    I just tried your code and it worked as expected for me. I suspect that you expect to see the marker moved by quite a large amount, but perhaps your units are small (millimetre?) so it doesn't look like the marker actually moved. I put in a larger number for the offset {100, 100, 0} and I can clearly see:
    • the parameterized marker is offset from the referenced marker,
    • the expression is proper (as you have shown in your image, which makes me think that your model is correct?)
    • I can move the reference marker and the slave marker moves properly.
     
    So I think that your code is correct. I do recall in a certain version of the code that you could run into an issue with the graphics not updating properly, so *perhaps* that is happening here, but I wonder if the 'delta' that you have used is simply too small to notice when you look at the model quickly?
     
    Hope this helps,
    Kent
     
  • Hi Niels,
     
    This looks like a View refresh bug to me, which we will report ASAP. My quick workaround is to use Adams.execute_cmd() instead of Adams.expression() and use the actual marker modify command to ensure that the marker does get placed where it should. Please check out the last line below:
     
    mod = Adams.Models.create(name='tester')
    g = mod.Parts["ground"]
    ref = g.Markers.create(name='ref', location=[0,0,0])
     
    m1=g.Markers.create(name='m1', location=[0,0,0])
    #m1.location = Adams.expression("(LOC_RELATIVE_TO({100.0,0.0,0.0}, %s))" % ref.full_name)
    Adams.execute_cmd("marker modify marker_name = m1 location = (LOC_RELATIVE_TO({100.0, 0.0, 0.0},"+ref.full_name+"))")
     
    I hope this helps.
     
    Thank you,
     
    Maziar Rostamian
    MSC Software
  • @Kent West​@Maziar Rostamian​ 
    In my Adams version '2020 FP1', the marker does not move, because when i press apply the marker is actually moving to the correct position. So this is most likely a view refresh bug as you guys mentioned. Thanks for the quick workaround!
     
    Just noticed that when i toggle icon visibility the marker actually shows up on the correct position but the name doesn't, hope this helps in solving the bug.
    image
  • Hi Niels,
     
    You can simply workaround this by creating a dummy model (in addition to your original model) and delete it immediately. You can add this to end of your code and markers will get refreshed.
     
    Adams.execute_cmd(" mod cre mod= dummy")
    Adams.execute_cmd(" mod del mod= dummy")
     
    Regards,
    Rishi