Grasshopper

algorithmic modeling for Rhino

Hi, I am exploring the ETABS api application with ghpython. I get stuck in trying to catch current opened ETABS application. I got error like the pic shows. Any suggestion in solving the problem? Thanks.

Views: 2519

Attachments:

Replies to This Discussion

From some samples I see, it looks like you need to run this as a function:

SapModel = myETABSObject.SapModel() #As ETABS2015.cSapModel


Giulio

--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Thanks for your reply. I tried your suggestion but the same error showed up. As my previous screenshot shows, the ETABSObject captured from Marshal ("csiApp") is different from a default one ("ETABS2015.cOAPI"), which has a different set of members. But from a sample code here (SAP2000 api is similar), the captured ETABSObject should be similar to a default one.

Ok, then my next step would be to try this in the Vb.Net component. If we are lucky, that might give us more insight. I see most samples online are in Vb.

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Well that works with Vb.Net. With either "AttachToInstance" True or False, the code works as expected. Not sure if it is because Vb.Net supports Interop better than ironpython.

  Private Sub RunScript(ByVal Run As Boolean, ByVal AttachToInstance As Boolean, ByRef ret As Object)
    If Run Then
      Dim ProgramPath As String = System.IO.Path.Combine(System.Environment.GetEnvironmentVariable("PROGRAMFILES"), "Computers and Structures", "ETABS 2016", "ETABS.exe")
      Dim myETABSObject As ETABS2016.cOAPI = Nothing
      ret = 0

      If AttachToInstance Then
        myETABSObject = DirectCast(System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.ETABS.API.ETABSObject"), ETABS2016.cOAPI)
      Else
        Dim myHelper As ETABS2016.cHelper
        myHelper = New ETABS2016.Helper
        myETABSObject = myHelper.CreateObject(ProgramPath)
        ret += myETABSObject.ApplicationStart()
      End If

      Dim mySapModel As ETABS2016.cSapModel
      mySapModel = myETABSObject.SapModel

      mySapModel = Nothing
      myETABSObject = Nothing
    End If
  End Sub

Hi David,

I don't have the program to test, but it looks like the Vb.Net code is significantly longer and more involved than the IronPython one. In the end, both should work the same, as the runtime on which they run is the same. In Rhino you are using IronPython, which is not the CPython version that is likely documented on the http://docs.csiamerica.com website, but a fully .Net-based one. Note that for COM Interop, the exact naming of member sometimes is not known till the call is actually run.

It might be that Vb.Net does some inner work for you, I cannot tell from just looking at the code. If you are only able to get it to work in Vb.Net, then maybe it's a good idea to use that language?

Also, think about the fact that Vb.Net "SapModel" could translate to "SapModel()" in IronPython. If you want to make it work in Python, I would try to write the exact same code as in Vb.Net.

Please let me know your next steps and findings :)

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Thanks again for your attention and sorry for the late reply.

I don't feel like continuing ETABS api with ironpython, since it cannot attach to a current running ETABS and even if I can create a new one, the reference cannot be transferred to the next python component for some reason I don't know. Plus, the CSI support said their developers only support Cpython.

Now I switched to VB.Net to interact directly with ETABS api, and that works like their api help document shows. I'm now building on definitions to retrieve model info and analysis results. May work on converting Rhino models to ETABS model later if my coding level becomes adequate.

Good to know, David. Awesome progress! :)

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service