CoCreate User Forum

CoCreate User Forum (https://www.cocreateusers.org/forum/index.php)
-   Customization (https://www.cocreateusers.org/forum/forumdisplay.php?f=12)
-   -   OSD => Save current WP into .mi file (https://www.cocreateusers.org/forum/showthread.php?t=7966)

Shaba 06-13-2012 02:22 AM

OSD => Save current WP into .mi file
 
How can i save current WP into a .mi file?

PHP Code:

(mi_out :select (sd-inq-obj-basename (sd-inq-curr-wp)))
(
mi_out :select (sd-inq-curr-wp)) 

I tye this but it doesn't work... :confused:
Some help?
TNX :cool:

Mike Swartz 06-13-2012 11:21 AM

Re: OSD => Save current WP into .mi file
 
Workplanes are stored as 3D data, not 2D (*.mi) so it's not going to happen.

It is also not possible to copy the 2d Data from a workplane and paste it into Annotaton or Drafting

Shaba 06-13-2012 10:50 PM

Re: OSD => Save current WP into .mi file
 
The command exist, everyday i use this command

From OSD:
Save => Data 2D (.mi) => I select a workplane => name_file_out.mi => OK

So i need only a macro that select in automatic the current workplane

Henk Stokkel 06-18-2012 12:46 AM

Re: OSD => Save current WP into .mi file
 
To store the geometry from a workplane I use this code in a macro of mine:
Code:

(sd-call-cmds
          (MI_OUT
            :filename name_of_file
            :overwrite
            :select name_workplane
          )


Shaba 06-18-2012 04:37 AM

Re: OSD => Save current WP into .mi file
 
are you sure it works?
Ti give me error.. :/

Henk Stokkel 06-21-2012 10:24 PM

Re: OSD => Save current WP into .mi file
 
It works fine by me. i use this in a macro to make slices of a 3D object so I can use these contours on a 2.5D milling machine.

Shaba 06-22-2012 02:02 AM

Re: OSD => Save current WP into .mi file
 
2 Attachment(s)
Look at this:
I don't understand.. :(

ludw 06-23-2012 12:34 AM

Re: OSD => Save current WP into .mi file
 
You should try the following:
Code:

(sd-call-cmds
  (MI_OUT
    :overwrite "c:/Temp/wp.mi"
    :select "/w1"
    )
  )

It works for me (18.1 release)

Shaba 06-23-2012 02:32 AM

Re: OSD => Save current WP into .mi file
 
For me works grest this:

PHP Code:

(MI_OUT :overwrite (format nil "~A.mi" (string-upcase (sd-inq-obj-basename (sd-inq-curr-wp)))) :select (sd-inq-curr-wp)) 

THANKS!!!
:cool:

Shaba 07-19-2012 12:42 PM

Re: OSD => Save current WP into .mi file
 
I have upgrade my code
But sometimes (i think the first time) give me error and then works well

Someone can help me?
TNX

PHP Code:

(setq des 96)
(
setf filename_mi_out (format nil "~A.mi" (string-upcase (sd-inq-obj-basename (sd-inq-curr-wp)))))
(
loop while (probe-file filename_mi_out) do
   (
setq des (incf des))
   (
setf filename_mi_out (format nil "~A~A.mi" (string-upcase (sd-inq-obj-basename (sd-inq-curr-wp))) (code-char des)))

);;while
(
MI_OUT
  
:overwrite filename_mi_out
  
:select (sd-inq-curr-wp)



Fred RINCE 02-26-2021 08:21 AM

Re: OSD => Save current WP into .mi file
 
Hi All,

It's a very very old post but i try save WP in MI with right button menu context.

I wrote that for menu:
(sd-browser-add-popup-entry
"parcel-gbrowser"
:entry-type :push
:label (sd-multi-lang-string "Save WP as..." :french "Enregister PdT sous..." )
:is-entry-applicable 'IsWPObj
:menu-action 'saveWP
:new-group t
)

and then, the function:
(defun saveWP (obj name)
(mi_out :filename (format nil "~A.mi" (string-upcase (sd-inq-obj-basename obj))) :overwrite :select (BrowserNode-objPath obj))
)

Doesn't works ! And Modeling crash....Any idea ??

Andy Poulsen 02-26-2021 10:50 PM

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

tom kirkman 03-01-2021 03:20 AM

Re: OSD => Save current WP into .mi file
 
I have this macro, that takes a workplane, saves it as an MI file and then loads it into annotation.

Code:

(sd-defdialog 'wp2anno
 
        :dialog-title "WP to Annotation"
 
        :variables
        '(
                (wptje :initial-value (sd-inq-curr-wp) :value-type :wp :title "Workplane")
        )

        :local-functions
          '(
                  (doit () 
                        (mi_out :select :workplane wptje :FILENAME "C:/working/out/plot.mi" :OVERWRITE )
                        (AM_LOAD_ANY_MI :FILENAME "C:/working/out/plot.mi") 
                )
        )
        :ok-action
        '(doit)
)


Fred RINCE 03-01-2021 09:13 AM

Re: OSD => Save current WP into .mi file
 
Hi Andy,

I'm very happy somebody answer me :-)....I was very surprise too, to have very quickly answer ! Nice !!
Of course, it works ! I will follow your advices to upgrade this program because, in fact, i want to select more than one WP from Browser and then, store them.
Very happy this forum is still alive !
Thank you for your help

Fred RINCE 03-01-2021 09:17 AM

Re: OSD => Save current WP into .mi file
 
Hi Tom,

Thank you too for your anwser. Like i said, it's very plaisant to see this forum is still alive. Many thanks.
I'm realy new in LISP Modeling code.


All times are GMT -8. The time now is 04:46 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.