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

How to Copy Polylines from One Drawing onto the Same Sport of a Sister Drawing?

33 REPLIES 33
SOLVED
Reply
Message 1 of 34
JC_BL
2630 Views, 33 Replies

How to Copy Polylines from One Drawing onto the Same Sport of a Sister Drawing?

I would like to know the way to correctly copy and paste selected polylines from one drawing onto the same spot of a sister drawing.

 

I am trying to do the following using AutoLISP:

  • My program opens a master-drawing, and create a simple layout in that drawing.  The layout covers everything on the drawing.
  • The program uses "ExportLayout" command to export the layout into a DWG file.  Let call this DWG file the "compressed drawing".  The purpose of doing this is to turn all the 3D objects into 2D and to significantly reduce the file size; then users can open that drawing in AutoCAD-360 without running the risk of hitting the maximum drawing file size limit of AutoCAD-360.
  • The program saves the compressed-drawing in AutoCAD-360 (it used to be called AutoCAD WS).
  • A user opens that compressed-drawing in AutoCAD-360, and he puts some polylines over some objects on the drawing to indicate that he has finished working on those objects.
  • My program gets the compressed drawing back from AutoCAD-360.
  • The program copies and pastes the polylines from the compressed-drawing into the master-drawing.  It uses "Copy with Base Points" and "Paste to Original Coordinates" to copy and paste.
  • The program uses the polylines to select the objects in the master-drawing.  It finds the entity handles of those selected objects and use the entity handles as the key to update some database tables.

Everything works _except_ the copying and pasting of the polylines.  I find that the polylines copied to the master drawing become very tiny and they are placed in the wrong place.  Seem like the origins / scales of the master drawing and the compressed drawing are different.

 

How do I find which origin and which scale the master drawing uses?

How do I change the compressed drawing to match the origin and the scale of the master drawing?

 

 

Please help me with these.  Thanks in advance for your help.

 

Jay Chan

33 REPLIES 33
Message 21 of 34
JC_BL
in reply to: hmsilva

Hello hmsilva,

 

I don't see anything different with the small DWG file (generated from EXPORTLAYOUT) after following the steps described in your message. The small DWG is still in paper space scale and its (0,0,0) coordinates are still off.

 

Yes, I can see the reference points (the text "llpt" and "urpt") that "demo" has added near the UCS. And they show up in both the master drawing and the small DWG, and they are in the correct layer "MyAlign".

 

May be the problem has to do with those two variables msllpt" and "msurpt" in demo1 are not defined?

 

By the way, I need to add the command (vl-load-com) in both demo and demo1 to get them running. But that doesn't affect the outcome.

 

Anyway, I will read your program to see if I can pickup something from it.

 

Jay Chan

Message 22 of 34
hmsilva
in reply to: JC_BL


@jchan wrote:

Hello hmsilva,

 

I don't see anything different with the small DWG file (generated from EXPORTLAYOUT) after following the steps described in your message. The small DWG is still in paper space scale and its (0,0,0) coordinates are still off.

 

Yes, I can see the reference points (the text "llpt" and "urpt") that "demo" has added near the UCS. And they show up in both the master drawing and the small DWG, and they are in the correct layer "MyAlign".

 

May be the problem has to do with those two variables msllpt" and "msurpt" in demo1 are not defined?

 

By the way, I need to add the command (vl-load-com) in both demo and demo1 to get them running. But that doesn't affect the outcome.

 

Anyway, I will read your program to see if I can pickup something from it.

 

Jay Chan


Hi Jay,

the "msllpt" and "msurpt" are defined in the first code, and were propagated with the vl-propagate function, if you open the small dwg after run the demo, should work as expected.

The vl-load-com my bad, I have the Visual LISP extensions always loaded....sorry

 

Henrique

EESignature

Message 23 of 34
JC_BL
in reply to: hmsilva

I check both msllpt and msurpt variables in the master drawing and the small DWG, they both are nil in both drawngs.

 

I have tried to debug "demo" and found that the variables psllpt and psurpt have coordinates in them (such as (1.04642 0.796417 0.0) and (9.41775 7.16775 0.0)).  But msllpt and msurpt variables are both nil.  I manually enter the following command at command prompt, and I find that the return value is nil:

 

(trans '(9.41775 7.16775 0.0) 3 2)

 

Seem like that command only works in layout tab.  It doesn't work in model space.

 

Jay Chan

Message 24 of 34
hmsilva
in reply to: JC_BL

Jay,

as I said in the message #20, to run the demo routine the master dwg must be in the layout tab.

 

Henrique

EESignature

Message 25 of 34
JC_BL
in reply to: hmsilva

Thanks for pointing out that the first part of the demo program needs to run in the Layout tab.

 

I still need to make one fix in order for the demo1 to run:  I need to remove msllpt and msurpt from the variable definition of demo1, like this:

 

Before:

   (defun demo1 (/ LL MSLLPT MSURPT UR)

After:

   (defun demo1 (/ LL UR)

 

Somehow, the local definition of those two variables hides the variables from (vl-propagate).

 

Now, I can run demo1 to stretch the objects in the small DWG to exactly the same size as the corresponding objects in the master drawing.  This is good.  However, there is still one problem.  The objects are placed too far left and low.  The (0,0,0) in the master drawing becomes (-36.* Ft,-10.* Ft, 0) in the small DWG.

 

Jay Chan

Message 26 of 34
hmsilva
in reply to: JC_BL


@jchan wrote:
...
The (0,0,0) in the master drawing becomes (-36.* Ft,-10.* Ft, 0) in the small DWG.

...


Jay

Is the 0,0,0 or the viewport lower left corner?

 

Henrique

EESignature

Message 27 of 34
JC_BL
in reply to: hmsilva

The (0,0,0) that I was referring to is the UCS of the master drawing.  And the UCS and WCS are the same in that drawing.

 

The lower left corner of the Layout tab of the master drawing is (0,0,0), and the layout is paper space and is the size of a letter size paper.

 

That (-36.* Ft, -10.* Ft, 0) difference in coordinates doesn't seem to correlate to anything in the master drawing or the small DWG.

 

Jay Chan

Message 28 of 34
hmsilva
in reply to: JC_BL

Jay,

I can't reproduce that behavior...

Are you setting OSMODE to zero, before run the demo1?

A simple test, try the code with the attached dwg.

 

Henrique

EESignature

Message 29 of 34
JC_BL
in reply to: hmsilva

Yes, I have used the following command to set OSMODE to zero:

 

(setvar "OSMODE" 0)

 

I have tested with your base_layout1.dwg file.  The program works fine -- meaning that the scale and coordinates of the small DWG match the master drawing (after the small DWG is stretched with demo1). The result is like this:

 

The reference line that is in the lower left corner of the master drawing (base_layout1.dwg) is

from (2.0811,0.8311,0.0000) to (3.0488,1.8149,0.0000).

 

The same reference line in the small DWG before being stretched is

from (2.0554,0.9401,0.0000) to (2.9567,1.8619,0.0000).

 

The same reference line in the small DWG before after the drawing was stretched using demo1 is

from (2.0811,0.8311,0.0000) to (3.0488,1.8149,0.0000) that is the same as the one in the master drawing.

 

The only thing different is that those two texts "llpt" and "urpt" are really BIG in my drawing, but are reasonably small in your drawing.

 

Seem like there is something in my drawing that doesn't work well with your program.

 

Jay Chan

Message 30 of 34
hmsilva
in reply to: JC_BL

Jay

make a copy of one of yours master dwg's, erase everything, purge, draw a few lines and post the dwg.

 

Henrique

EESignature

Message 31 of 34
JC_BL
in reply to: hmsilva

Attached please find a trimmed down version of the original master drawing.  You can see a small reference point (a circle) right at the UCS, and two polylines in the lower left corner away from the UCS - one pink one blue.

 

I have tested this drawing with your program, and I still have the exact same problem with this drawing.

 

Thanks in advance if you can find out what is causing the problem.

 

Jay Chan

Message 32 of 34
hmsilva
in reply to: JC_BL

Hi Jay,

the problem was with the TARGET SysVar, to avoid this, try the attached code

(defun c:demo ( / LL MSLLPT MSURPT PSLLPT PSURPT UR VLAOBJ VP)
  (if (setq vp (ssget "x" '((0 . "viewport") (-4 . "/=") (69 . 1))))
    (progn
      (setq VlaObj (vlax-ename->vla-object (ssname vp 0)))
      (vla-put-target VlaObj (vlax-3d-point '(0 0 0)))
      (vlax-invoke-method VlaObj 'GetBoundingBox 'll 'ur)
      (setq psllpt (vlax-safearray->list ll)
	    psurpt (vlax-safearray->list ur)
	    msllpt (trans psllpt 3 2)
	    msurpt (trans psurpt 3 2)
      )
      (vl-propagate 'msllpt)
      (vl-propagate 'msurpt)
      (entmake
	(list
	  (cons 0 "TEXT")
	  (cons 100 "AcDbText")
	  (cons 8 "MyAlign")
	  (cons 10 psllpt)
	  (cons 40 (getvar 'TEXTSIZE))
	  (cons 1 "llpt")
	  (cons 100 "AcDbText")
	)
      )
      (entmake
	(list
	  (cons 0 "TEXT")
	  (cons 100 "AcDbEntity")
	  (cons 8 "MyAlign")
	  (cons 10 psurpt)
	  (cons 40 (getvar 'TEXTSIZE))
	  (cons 1 "urpt")
	  (cons 100 "AcDbText")
	)
      )
    )
  )
  (princ)
)

HTH

Henrique

 

EESignature

Message 33 of 34
JC_BL
in reply to: hmsilva

The script works very good now.

 

What I have learnt from your program are:

 

1.  The way to get access to the viewport of a layout tab.

 

2.  I can use (vl-propagate) to save the info from the master drawing session to the small DWG session.  Then I don't need to store the info (such as the scale-up factor) into a text file.

 

3.  The way to create an entity directly into a drawing (as a reference point) using (entmake).

 

4.  Finally the command ALIGN that use two objects as reference points to align everything in the drawing - that can correct the scale and the coordinates all at once.

 

Thanks for your help.

 

Jay Chan

Message 34 of 34
hmsilva
in reply to: JC_BL

You're welcome, Jay
Glad I could help

Henrique

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost