Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

lisp code to store clipboard data as dwg file

20 REPLIES 20
SOLVED
Reply
Message 1 of 21
GeryKnee
960 Views, 20 Replies

lisp code to store clipboard data as dwg file

 

I need lisp code to store the current drawing clipboard data as a dwg file

Can anyone help me?

20 REPLIES 20
Message 2 of 21
Kent1Cooper
in reply to: GeryKnee

Could you use WBLOCK instead of COPYCLIP or COPYBASE, to send a selection out as a drawing directly, rather than by way of the Clipboard?

Kent Cooper, AIA
Message 3 of 21
Shneuph
in reply to: GeryKnee

I'm pretty this example is key to what you are trying to do (directly from ActiveX Reference Guide)... but I dont' have experience with it.

 

CopyObjects method

 

Scroll to the VBA example at the bottom.  Hopefully someone else can elaborate to your specific request.

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 4 of 21
GeryKnee
in reply to: Kent1Cooper

 

In a drawing A.dwg i copy to clipboard some objects (CTRL+C)

I need to insert the clipboard data to another B.dwg, but i need to scale the block of them

Using Ctrl+V or Ctrl+Alt+V the Clipboard Data are inserting without the ability to scale them (as Autocad R14 were doing)

Using -insert i have the ability to scale a block but, in order to do this you have to refere to a block.

So the clipboard data have to be stored to a file in a supported path to use the file name.

Thats what i try to do

I need a lisp code that exports the clipboard data to a dwg file but i don't how to do it and if it's possible to do.

Thanks,

Gery

Message 5 of 21
Kent1Cooper
in reply to: GeryKnee


@GeryKnee wrote:

 

....

Using -insert i have the ability to scale a block but, in order to do this you have to refere to a block.

So the clipboard data have to be stored to a file in a supported path to use the file name.

....


The Insert command can also Insert an external drawing file [i.e. you don't have to refer to a Block already defined in the drawing].  It becomes a Block definition in the drawing in which it is Inserted.  The Wblock command will make that external drawing file with a selection of objects.  Rather than selecting them and using Ctrl-C to copy them to the Clipboard, and then making them into a drawing from there, use Wblock instead to make them into a drawing directly, without the Clipboard as a middle-man.  You can then Insert that drawing [with an Insert command instead of the PasteBlock command that Ctrl-Shift-V does], including scaling and all other Insert choices, into any other drawing.

 

It will ask for an insertion point, so it's like the Copybase command [Ctrl-Shift-C] rather than Copyclip [Ctrl-C].  And it will ask for a drawing name, but you could use something temporary, dedicated to this usage.  For example, if you have a routine that does it using a name such as "Transfer", you can name it differently as a Block in another drawing [your Drawing B] by using the Insert command with the "Blockname=Filename" usage, e.g. Insert "TrashCan=Transfer" and you'll end up with a Block in Drawing B called "TrashCan" which contains the things you selected in Drawing A and Wblocked out of it.

 

If you do it with Wblock in a (command) function rather than using the dialog box, it will always remove the selected objects from the current drawing [that's an option in the dialog box].  But you can bring them back immediately with the Oops command, to have an end result more like Copyclip which leaves them in the drawing.

Kent Cooper, AIA
Message 6 of 21
GeryKnee
in reply to: Kent1Cooper

Thanks Kent for your care

The problem is that using -Wblock to select the objects , you are asked you to give the export file name via dialog , you hane not the ability to give it as :

COMMAND LINE ::: -WBLOCK

AUTOCAD PROMPT :::  file name -> you give your temp file name

You have always to use the browsing dialog that the command opens and that's not the best and something is

 1) unnecessary

 2) unmanageable

 

Gery

 

Message 7 of 21
hmsilva
in reply to: GeryKnee


@GeryKnee wrote:

 

In a drawing A.dwg i copy to clipboard some objects (CTRL+C)

I need to insert the clipboard data to another B.dwg, but i need to scale the block of them

Using Ctrl+V or Ctrl+Alt+V the Clipboard Data are inserting without the ability to scale them

...

I need a lisp code that exports the clipboard data to a dwg file but i don't how to do it and if it's possible to do.

...


Something like this perhaps.
(defun c:cb (/ pt ss);; to copy to clipboard
  (if (and (princ "\nSelect entities to copy with base point: ")
	   (setq ss (ssget))
	   (setq pt (getpoint "\nSpecify base point: "))
      )
    (command "_.copybase" pt ss "")
  )
  (princ)
)

(defun c:pb (/ l l1);; to paste as block, scale and explode
  (command "_.pasteblock" pause)
  (command "_.scale" "_L" "" (getvar 'LASTPOINT))
  (while (> (getvar 'cmdactive) 0)
    (command pause)
  )
  (command "_.explode" "_L")
  (princ)
)

 

Hope that helps
Henrique

EESignature

Message 8 of 21
Kent1Cooper
in reply to: GeryKnee


@GeryKnee wrote:

Thanks Kent for your care

The problem is that using -Wblock to select the objects , you are asked you to give the export file name via dialog ....


Not when you're in an AutoLISP (command) function, in which Command:-line operation is the default, without the dialog box -- you need to specifically ask for it with (initdia) beforehand if you want it.  The following works for me [in 2015 -- I'll try later in an older version to see whether the syntax might be any different], to make a drawing with the current drawing's 0,0,0 location as its insertion point, containing the last-drawn entity in the current drawing:

 

(command "_.wblock" "c:/temp/transfer.dwg" "_yes" "" '(0 0 0) "_last" "" "_oops")

 

You would substitute whatever you want as an insertion point in place of '(0 0 0), and a selection set in place of "_last", which you can get similarly to those parts of hmsilva's suggestion.

 

The "_yes" is there in case you've used this before, to overwrite the previous transfer drawing.  It won't care if it doesn't exist yet -- a message will go by that it can't find a Block by that name [assuming you don't have one], but it will carry on.  Alternatively, you could make it check first whether there's such a drawing already, and if so, delete it so Wblock won't ask whether you want to replace it.

Kent Cooper, AIA
Message 9 of 21
GeryKnee
in reply to: hmsilva

thanks Henrique

that's what i needed exactly.

 

Message 10 of 21
GeryKnee
in reply to: hmsilva

 Dear Henrique,

Something Else.

Mayby it's posiible to set default value to scale (the value of 1)

If the previeous use of the command used scale for example 2.3 then the next use initializes scale factor to thi value of 2.3

I wonder if this initial value sould be always 1 so, user sould have scale factor=1.00 by clicking rigtht click.

Thanks,

Gery

Message 11 of 21
hmsilva
in reply to: GeryKnee

You're welcome, Gery.

 

Sorry, but I don't know where the scale last value is stored, so, to force the default scale value to one, perhaps something like this.

Quick and dirty...

 

(defun c:pb (/ l l1);; to paste as block, scale and explode
  (command "_.pasteblock" pause
	   "_.scale" "_L" "" (getvar 'LASTPOINT) 1
	   "_.scale" "_L" "" (getvar 'LASTPOINT))
  (while (> (getvar 'cmdactive) 0)
    (command pause)
  )
  (command "_.explode" "_L")
  (princ)
)

 

Henrique

EESignature

Message 12 of 21
Kent1Cooper
in reply to: GeryKnee


@GeryKnee wrote:

....

I need to insert the clipboard data to another B.dwg, but i need to scale the block of them

Using Ctrl+V or Ctrl+Alt+V the Clipboard Data are inserting without the ability to scale them (as Autocad R14 were doing)

....


Are you sure about that?  You don't say what version you are using, but in my 2015 at least, you definitely can scale what you paste in with Ctrl+V and Ctrl+Shift[notAlt]+V.  When it asks for an insertion point, type S and it will ask for a scale.  It doesn't offer the option in the prompt, but the option is there.  When I Ctrl+C some things out of one drawing, and in another hit Ctrl+Shift+V, I get:

 

Command: _pasteblock Specify insertion point: S
Specify scale factor for XYZ axes <1>:

 

And similarly with Ctrl+V, coming in not as a Block but separately -- no need to bring them in as a Block and Explode it.

Kent Cooper, AIA
Message 13 of 21
hmsilva
in reply to: Kent1Cooper


@Kent1Cooper wrote:
... but in my 2015 at least, you definitely can scale what you paste in with Ctrl+V and Ctrl+Shift[notAlt]+V.  When it asks for an insertion point, type S and it will ask for a scale.  It doesn't offer the option in the prompt, but the option is there.  When I Ctrl+C some things out of one drawing, and in another hit Ctrl+Shift+V, I get:

 

Command: _pasteblock Specify insertion point: S
Specify scale factor for XYZ axes <1>:

 

And similarly with Ctrl+V, coming in not as a Block but separately -- no need to bring them in as a Block and Explode it.


In 2010 works ok with the option S...

I didn't know that option for scale existed in pasteclip/pasteblock command.

Thank you Kent.

 

Henrique

EESignature

Message 14 of 21
GeryKnee
in reply to: hmsilva

 

Yes,

This is working perfectly.

Thats all i want

Thanks for all,

 

Regards,

Gery

Message 15 of 21
GeryKnee
in reply to: hmsilva

 

As my problem has been whole solved, i thank you all who cared to find a solution.

Regards,

Gery

 

Message 16 of 21
GeryKnee
in reply to: hmsilva

Sorry Henrique,

One last trial.

Sould the Scale be different in the two directions X, Y  (Scale X and Scale Y)

What is the lisp code in that case?

Gery

Message 17 of 21
hmsilva
in reply to: GeryKnee


GeryKnee wrote:

Sould the Scale be different in the two directions X, Y  (Scale X and Scale Y)

What is the lisp code in that case?


Something like this, perhaps...

 

(defun c:pb (/ h obj v);; to paste as block, scale and explode
  (vl-load-com)
  (command "_.pasteblock" pause)
  (setq obj (vlax-ename->vla-object (entlast)))
  (initget 6)
  (setq h (getreal "\nEnter Horizontal Scale <1.00>: "))
  (if (not h)
    (setq h 1.00)
  )
  (initget 6)
  (setq v (getreal (strcat "\nEnter Vertical Scale <" (rtos h 2 2) ">: ")))
  (if (not v)
    (setq v h)
  )
  (vla-put-xscalefactor obj h)
  (vla-put-yscalefactor obj v)
  (command "_.explode" "_L")
  (princ)
)

 

HTH

Henrique

EESignature

Message 18 of 21
GeryKnee
in reply to: hmsilva

This code does not get the scaleX and Scale Y using the Screen plus entering the rael values (by Keyboard) as it was working good in the previous code (useing the simple variable scale).

Meyby a change to code will make it working as the previous (entering the scale variable graphically as distance of LASTPOINT and User defined for both X and Y direction.

The LASTPOINT must be the block insertion point for both X and Y direction.

I hope it's possible for you to change the code.

I'm waiting your reply.

Regards,

Gery

 

Message 19 of 21
hmsilva
in reply to: GeryKnee


@GeryKnee wrote:

This code does not get the scaleX and Scale Y using the Screen plus entering the rael values (by Keyboard) as it was working good in the previous code (useing the simple variable scale).

Meyby a change to code will make it working as the previous (entering the scale variable graphically as distance of LASTPOINT and User defined for both X and Y direction.

The LASTPOINT must be the block insertion point for both X and Y direction.

I hope it's possible for you to change the code.

I'm waiting your reply.

Regards,

Gery

 


The previous code use the SCALE command to scale the pasted entities, and only allows to scale uniformly, as you have asked to be able to to scale with different x y values, the above code allows to enter different x y values and the base point will be the block insertion point for the x and y scale...

To change the x/y scales dynamically would require much more code lines and and more free time for writing it, and free time is what I don't have right now...

 

Henrique

EESignature

Message 20 of 21
GeryKnee
in reply to: hmsilva

OK,

I'll se the previous code and maybe in the future you'll hve the time to lokk at it again.

Thanks,

Gery

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost