View Single Post
  #12  
Old 02-26-2021, 10:50 PM
Andy Poulsen Andy Poulsen is offline
Administrator
 
Join Date: Apr 2003
Location: Fort Collins, Colorado
Posts: 273
Re: OSD => Save current WP into .mi file

Hi Fred,

The reason it doesn't work is that calling functions from the structure browser uses different object types (and when the call fails, it can crash Modeling as you noticed).

The problems are in the saveWP function -- you're trying to get the basename of a browser object, which is different from a regular Modeling object.

One thing that can help with functions like this is to break the "decoding" into multiple steps so you can check them along the way. Also, if you use "sd-put-buffer" to make the call, it's less likely to crash Modeling since calls made from the command-line (which is essentially what sd-put-buffer does) have much more robust error handling. You could also have the popup call a dialog, which would also provide more robust error handling.

So, if you make the function have a few more steps, it should work:
Code:
(defun saveWP (obj name)
  ;; create some temporary variables for this function to use
  (let (path fname cmdstr)
    ;; extract the path to the Modeling object
    (setq path (BrowserNode-objPath obj))
    ;; create the filename. Note that we first need to get the object pointed to
    ;;      by the path, and then get that object's basename
    (setq fname (format nil "~A.mi" (string-upcase (sd-inq-obj-basename (sd-pathname-to-obj path)))))
    ;; create the command string that we want to execute, including quotes
    (setq cmdstr (format nil "mi_out :select \"~a\" :filename \"~a\" :overwrite" path fname))
    ;; now execute the command string as though we had typed it into the user input line
    (sd-put-buffer cmdstr)
    )
  )
I hope this helps! If you have any other questions, just ask!

andy
__________________
Andy Poulsen
AI MAXTools: Dream. Design. Done. It's that easy!
Add-ins bringing new functionality and speed to Creo Elements/Direct and CoCreate products. Now available for v17-v20+!
See them in action at www.ai-maxtools.com and then try them for yourself -- FREE!
Reply With Quote