Do the newly created layouts and viewports need to be added to the block table record and transaction as they were done in this included example? This example is somewhat similar to what I am hoping to have created.
Looking pretty neat!
Do you think it could also help if you simplified the code to only work with the current Layout (Layout1) that is already in the drawing. In my work, we would not need to copy the layout multiple times as the code currently works. We would just need to go the the Layout1 already in the file and update the viewport parameters (View Center, View Height, View Width, Twist). Could this help simplify the code?
@hosneyalaa I have figured out part of the problem. the vport.TwistAngle command needs to be in radians for it to work correctly (see image below). The problem with this command is that it rotates the actual viewport in PaperSpace, not the View of the viewport in modelspace.
I think I have determined that the command I should use is view.ViewTwist (see image below) The issue that I am having is that the ViewTwist command rotates the view about the points (0,0). I need to rotate the view about the center of the rectangle, which is IN[0] for the program. When you have some time could you take a look and see what needs to be adjusted to rotate about the input IN[0]. I have attached an updated DWG to try. Thanks!
Part Catalog Test Drawing Sheet.dwg (656.4 KB)
Hi
I’m not able using the ViewTableRecord()
method Fully
But I tried to use viewport.TwistAngle Via Lisp
it was working very well without any errors Also,
it is possible to use the command DVIEW.tw
That works
The coding part of the above is completely over my head but would it be possible to use the UCS to set the view rotation.
So set the sheet layouts up in model space as you have done, set a new ucs for every sheet using the bottom left corner, name it something that matches the block/sheet layout i.e. sheet 1, 2 etc, then add into the script to read the UCS and set that view for the view port?
Entirely doable, but someone would have to code it up.
Do someone know how to use that code above and change it just to do the next:
I already identify my viewports by handle, I want to go inside the viewport and execute whether it’s a lisp or a dynamo script I have both but still don’t know how to get inside the viewport.
I have the python code to support creating viewport on layout with a rotation angle.
I will gladly share it with anyone.
Feel free to direct message me and i can send to you.
This is an old post at this point, but I have been working an update to what was provided above. The new script should be able to set the viewport extents for a folder of DWGs based on inputs from an excel spreadsheet. I am having issues getting this graph to run completely so posting to see if anyone has advice.
The graph seems to get hung up after opening the first drawing (I’m not seeing the viewport set and the DWG is left open (not saved & closed)) but not seeing any errors from Dynamo.
SP001.dwg (964.0 KB)
SP002.dwg (962.3 KB)
CreateGrid.xlsx (9.2 KB)
BVSPC_ImportGridInformation_rev1.dyn (111.5 KB)
# Load the Python Standard and DesignScript Libraries
import clr
import os
# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
import Autodesk.AutoCAD.ApplicationServices.Application as acapp
# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
import Autodesk.AutoCAD.ApplicationServices.DocumentCollectionExtension
# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
#bring in folder path where .dwg files are located
vector = IN[0]
sheet = IN[1]
vh = IN[2]
vw = IN[3]
rotation = IN[4]
directory = IN[5]
#get list of files in folder path
fileList = os.listdir(directory)
#remove any files that do not have extension .dwg
fileList2 = [f for f in fileList if ".dwg" in f]
#create list of file paths
pathList = [directory+"\\"+f for f in fileList if ".dwg" in f ]
#Open Document For Write
for path in pathList:
adoc = DocumentCollectionExtension.Open(acapp.DocumentManager, path, False)
acapp.DocumentManager.CurrentDocument = adoc
vector = [vector]
sheet = [sheet]
error_report = None
res = []
object_ids_list = []
ret = True
try:
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
ii = 0
for i in sheet:
lm = LayoutManager.Current.CurrentLayout =sheet[ii]
lmm = LayoutManager.Current
objly = t.GetObject(lmm.GetLayoutId(lmm.CurrentLayout), OpenMode.ForWrite)
vids = objly.GetViewports()
vport = t.GetObject(vids[0], OpenMode.ForWrite)
vport.Locked = False
ed.SwitchToModelSpace()
view = ViewTableRecord()
view.CenterPoint =Point2d(vector[ii].X ,vector[ii].Y )
#viewtwist should be positive for clockwise rotation
view.ViewTwist = rotation
view.Height = vh
view.Width = vw
ed.SetCurrentView(view)
vport.Locked = True
ed.SwitchToPaperSpace()
vport.Locked = True
res.append(view)
ii +=1
t.Commit()
if adoc:
DocumentExtension.CloseAndSave(adoc, path)
except:
import traceback
error_report = traceback.format_exc()
if error_report is None:
OUT = res
else:
OUT = error_report
# Assign your output to the OUT variable.
#OUT = error_report