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:
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
Solved! Go to Solution.
Solved by GTVic. Go to Solution.
Would this solve the problem?
(command "ucs" "World") ' copy stuff (command "ucs" "Prev") (command "ucs" "World") ' paste stuff (command "ucs" "Prev")
I don't really know how you would do what you intend and am not sure a programmatic solution would be a feasible use of your time. Exportlayout creates a modelspace that contains the contents of both the model viewports and the paper space. So it creates a mixed unit, mixed scale mish-mash with no-real backward links to the original. You would have to develop a method of recognizing each viewport, it's scale and view center.
One possible solution would be to create a second exportlayout drawing with legend markers interpreting the various scales to allow you to rebuild the backward links.
If that is not the approach you want, you would need to use trans for each viewport in the modelspace (viewport ename to paperspace ename). Pasteorig should be to paperspace in the master drawing. From there, the program would have to select objects within a window that encompassed paper space and other viewport spaces.
@Anonymous wrote:
No, that doesn't work. May be I don't do what you have suggested in the correct context. What I did is to use your method to copy the polylines from the DWG file that was generated using EXPORTLAYOUT command, and then use your method to paste the polylines onto the master-drawing. This doesn't work -- meaning that the polylines are pasted to the wrong spot.
Seem like the problem has to do with the offset of the Layout (and the resulted DWG file) is different from the offset of the master-drawing. And I need to figure out what the offset of the Layout (and the resulted DWG file) and then compensate for the offset when I paste the polylines back to the master-drawing.
I am still looking...
Jay Chan
Sorry, my fault for not reading carefully about the layout export.
Copy with base point is good. Paste to Original Coordinates is an issue. I think the regular paste would be best, then you can pick a common point. That will not solve the rotation scale issue but it will solve the location problem.
I'm trying to think of a low-tech solution.
(defun c:paste_selectp ( / lastent paste_ss ) (setq lastent (entlast) paste_ss (ssadd)) (command "PASTECLIP") (while (= (getvar "CMDNAMES") "PASTECLIP") (command pause)) (while (setq lastent (entnext lastent)) (ssadd lastent paste_ss)) (command "SELECT" paste_ss "") (princ "\nDone - Pasted Entities are Now Previous Selection") (princ))
This function will rotate, move and scale entities based on 4 reference points:
(defun c:transform ( / ss angbase angdir p1 p2 p3 p4 a1 a2 d1 d2 )
(setq ss (ssget))
(setq p1 (getpoint "\nPoint 1 on New Entity: ")
p2 (getpoint "\nPoint 2 on New Entity: "))
(setq p3 (getpoint "\nPoint 1 on Reference Entity: ")
p4 (getpoint "\nPoint 2 on Reference Entity: "))
(setq a1 (angle p1 p2)
a2 (angle p3 p4))
(setq d1 (distance p1 p2)
d2 (distance p3 p4))
(setq angbase (getvar "angbase")
angdir (getvar "angdir"))
(command "undo" "begin")
(setvar "angbase" 0)
(setvar "angdir" 0)
(if (/= a1 a2) (command "rotate" ss "" p1 (angtos (- a2 a1) 0 8)))
(if (/= d1 d2) (command "scale" ss "" p1 (/ d2 d1)))
(command "move" ss "" p1 p3)
(setvar "angbase" angbase)
(setvar "angdir" angdir)
(command "undo" "end")
(princ))
The end result is that p1 and p2 will match p3 and p4
Hi jay,
like you said previously, your layout is a single viewport, scaled to fit all model, so before the Export Layout to Model, you can use the viewport object or one block or other pre-defined object, store two model space coordinated points with xdata, text, attributes or another method, and use the trans function go to translate the viewport coordinates to the model coordinates, then open the exported dwg, read the stored coordinates, move and scale the new dwg...
As a demo,
(setq VlaObj (vlax-ename->vla-object (car (entsel "\nSelect a Viewport : ")))) (vlax-invoke-method VlaObj 'GetBoundingBox 'll 'ur) (setq psllpt (vlax-safearray->list ll)) (setq psurpt (vlax-safearray->list ur)) (setq msllpt (trans psllpt 3 2));; the viewport lower-left point - model space coordinates (setq msurpt (trans psurpt 3 2));; the viewpor upper right point - model space coordinates
HTH
Henrique
Thanks. I finally come very close to find a way to copy the polylines from a DWG (generated from EXPORTLAYOUT) to the correct spot in the original drawing.
The way that I use is very similar to what you have suggested:
1. Add a small 1" circle right at the UCS of the Model Space of the master drawing. Make sure the circle is placed on a special layer that I am sure no drawings will have. It is the reference point.
2. Create the paper-space layout as usual.
3. Use the following command to find the scale-down factor of the paper-space layout:
(setq nScaleDownFactor (- (car (trans '(1 0 0) 2 3)) (car (trans '(0 0 0) 2 3)) ) )
4. Convert the scale-down factor into a scale-up factor (scale-up = 1 / scale-down). Save it into a text file. I could have saved it within the drawing file as an object. Saving in a text file is a tried and true method and I stick with this.
5. Use EXPORTLAYOUT command to generate a small DWG file from the paper-space layout as usual.
6. Open that small DWG file (that was from EXPORTLAYOUT), explode everything in order to reach the reference point. Find the reference point based on the fact that the reference point is a circle and it is on the special layer.
7. Get the coordinates of the reference point and convert into a list. The list is like (2.568 5.789 0), and that is in term of the location of the paper-space.
8. Use the SCALE command, and feed it with the coordinate of the reference point and the scale-up factor. Now, the small DWG file should have the same scale and the same UCS of the master drawing. Save the small DWG.
From here on, I can simply use "Copy with Base Point" command and the "Paste to Original Coordinates" command to copy and paste the polylines from the small DWG file to the master drawing.
No, I still have some work to do. The reason is that the polylines that the program pastes onto the original drawing are still "slightly" off. Their scales are correct; but their locations are just a little bit off (like +2"-X and +7"-Y). May be there are some decimal places mistakenly rounded off or something. Nevertheless, I can see that I am on the right track.
Thanks for all the help that I have received from people in this forum. I appreciate that.
Jay Chan
Jay,
just trying to understand your workflow.
Is the original master drawing in WCS or UCS?
Is the Viewport just scaled to fit the entire master drawing, without rotating the UCS?
Henrique
@Anonymous wrote:
The drawing is in WCS. Although the WCS and UCS are the same in most of our drawings, for the sake of "just in case", I should stick with WCS. I will use the default layout settings that is sale-to-fit the entire master drawing.
Jay Chan
As a "demo"
In the master drawing in the layout
(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))) (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) )
Do the export layout to model command, erase the recently created texts and layer,
Open the new dwg, set osmode to 0 and run the demo1
(defun c:demo1 (/ LL MSLLPT MSURPT UR) (if (and (setq ll (ssget "x" '((0 . "Text") (8 . "MyAlign") (1 . "llpt")))) (setq ur (ssget "x" '((0 . "Text") (8 . "MyAlign") (1 . "urpt")))) msllpt msurpt ) (progn (setq ll (cdr (assoc 10 (entget (ssname ll 0)))) ur (cdr (assoc 10 (entget (ssname ur 0)))) ) (command "align" "_all" "" ll msllpt ur msurpt "" "Y") ) ) (princ) )
erase the texts and layer...
The new dwg should be scaled and at the original coodinates.
HTH
Henrique
Can't find what you're looking for? Ask the community or share your knowledge.