Author Topic: Copy to Clipboard within a function/lisp  (Read 3994 times)

0 Members and 1 Guest are viewing this topic.

Danielbot

  • Guest
Copy to Clipboard within a function/lisp
« on: August 28, 2018, 11:40:53 AM »
Hello,

New member here. I am really bad at writing lisps. I created a lisp will do a bunch of stuff before we WBlock out of AutoCAD and then revert those changes so it looks like nothing ever happened. The only issue that I have is that once we get to the WBlock function, a window pops up asking us where to save the file. Inside the filename field, its empty. I don't know if there is a way to have that field automatically filled in with the drawing name before hand so I decided to see if I could get a lisp to copy the drawing name to the clipboard so that we can just do a paste when that window comes up. I found one on here that does it that now I need to put these functions together into one so it will copy the drawing name first and then run the rest of the lisp.

Here is what I have:

Code - Auto/Visual Lisp: [Select]
  1. (defun C:UploadWBlock ()
  2.   (Command "-Layer" "S" "0" "") ;Sets Current Layer to 0
  3.   (Command "-XREF" "D" "*") ;Detaches all Xrefs
  4.   (command "-Layer" "F" "*Size*,*Alias*,*Anno*,*Elev*,*Number*,*FW*,*Tag*" "") ;Freezes all layers that contain the text
  5.   (Command "HideSelected" (SSGet "X" '((0 . "LINE,CIRCLE,SPLINE,POLYLINE,DIMENSION,LEADER"))) "") ;Hides all objects that fall into that category
  6.   (Command "UCS" "W" "")
  7.   (Command "-WBlock" "~" "*")
  8.   (Command "Undo" "5")
  9.   (Alert "Your drawing has been exported and current drawing reverted back to it's original state before the export.")
  10. )
  11.  
  12. (defun C:DwgToClip (/ html result)
  13.     (setq
  14.         html (vlax-create-object "htmlfile")
  15.         result (vlax-invoke (vlax-get (vlax-get html 'ParentWindow) 'ClipBoardData) 'SetData "Text" (GetVar 'dwgname))
  16.     )
  17.     (vlax-release-object html)
  18.     result
  19. )
  20.  
« Last Edit: August 28, 2018, 12:59:53 PM by Danielbot »

Danielbot

  • Guest
Re: Copy to Clipboard within a function/lisp
« Reply #1 on: August 28, 2018, 02:15:17 PM »
Hello,

New member here. I am really bad at writing lisps. I created a lisp will do a bunch of stuff before we WBlock out of AutoCAD and then revert those changes so it looks like nothing ever happened. The only issue that I have is that once we get to the WBlock function, a window pops up asking us where to save the file. Inside the filename field, its empty. I don't know if there is a way to have that field automatically filled in with the drawing name before hand so I decided to see if I could get a lisp to copy the drawing name to the clipboard so that we can just do a paste when that window comes up. I found one on here that does it that now I need to put these functions together into one so it will copy the drawing name first and then run the rest of the lisp.

Here is what I have:

Code - Auto/Visual Lisp: [Select]
  1. (defun C:UploadWBlock ()
  2.   (Command "-Layer" "S" "0" "") ;Sets Current Layer to 0
  3.   (Command "-XREF" "D" "*") ;Detaches all Xrefs
  4.   (command "-Layer" "F" "*Size*,*Alias*,*Anno*,*Elev*,*Number*,*FW*,*Tag*" "") ;Freezes all layers that contain the text
  5.   (Command "HideSelected" (SSGet "X" '((0 . "LINE,CIRCLE,SPLINE,POLYLINE,DIMENSION,LEADER"))) "") ;Hides all objects that fall into that category
  6.   (Command "UCS" "W" "")
  7.   (Command "-WBlock" "~" "*")
  8.   (Command "Undo" "5")
  9.   (Alert "Your drawing has been exported and current drawing reverted back to it's original state before the export.")
  10. )
  11.  
  12. (defun C:DwgToClip (/ html result)
  13.     (setq
  14.         html (vlax-create-object "htmlfile")
  15.         result (vlax-invoke (vlax-get (vlax-get html 'ParentWindow) 'ClipBoardData) 'SetData "Text" (GetVar 'dwgname))
  16.     )
  17.     (vlax-release-object html)
  18.     result
  19. )
  20.  

Alright, I found a work around. Instead of having in the same block of code, I just used the Load and C:DwgToClip to run at the beginning.
« Last Edit: August 31, 2018, 11:52:28 AM by Danielbot »

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Copy to Clipboard within a function/lisp
« Reply #2 on: August 28, 2018, 02:46:23 PM »
a window pops up asking us where to save the file. Inside the filename field, its empty.
What if you set filedia to 0 prior to running the wbock command?

Code: [Select]
Command: FILEDIA

Enter new value for FILEDIA <0>:

Command: -WBLOCK
Enter name of output file: file
TheSwamp.org  (serving the CAD community since 2003)

Danielbot

  • Guest
Re: Copy to Clipboard within a function/lisp
« Reply #3 on: August 29, 2018, 10:00:25 AM »
a window pops up asking us where to save the file. Inside the filename field, its empty.
What if you set filedia to 0 prior to running the wbock command?

Code: [Select]
Command: FILEDIA

Enter new value for FILEDIA <0>:

Command: -WBLOCK
Enter name of output file: file

I actually wanted a dialogue to pop up. The default would have you have define the file path and filename (i.e. Enter Location: C:\users\daniel\NewDrawing.dwg). I wanted to prevent my designers from doing this because it leaves room for error when typing it manually and/or selecting the wrong file when they copy the file path.

After some testing though, part of the lisp doesn't work anymore. It won't hide the polylines. I'm actually trying to hide the revision clouds, it seems AutoCAD defines them as polylines but they won't go away  :cry:

ChrisCarlson

  • Guest
Re: Copy to Clipboard within a function/lisp
« Reply #4 on: August 30, 2018, 03:33:52 PM »
Replace POLYLINE with LWPOLYLINE

Danielbot

  • Guest
Re: Copy to Clipboard within a function/lisp
« Reply #5 on: August 31, 2018, 11:33:38 AM »
Replace POLYLINE with LWPOLYLINE

Wow, I feel really stupid now. I was 99% sure I tried that a long time ago and it didn't work. Tried it again just now and it worked.

Thanks!