.NET

Reply
Valued Contributor
bikelink
Posts: 54
Registered: ‎11-25-2001
Message 1 of 6 (363 Views)

viewport Number -1 ?

363 Views, 5 Replies
02-12-2009 01:09 AM
Hi, I have created 2 viewport in my layout via code.
1 of this , has property Number -1. No one error during creation ...but it's have number -1. Object id is valid.
Then when i try to get it in writemode an error occurred. Any suggestion ?
Valued Contributor
bikelink
Posts: 54
Registered: ‎11-25-2001
Message 2 of 6 (363 Views)

Re: viewport Number -1 ?

02-12-2009 01:43 AM in reply to: bikelink
If the size of viewport is >= of layout dimension -1 si returned
as soon you have created a viewport with dimension inside layout the number increase...
example:

1 layout 210x297
creation viewport with same size--> -1 returned
creation viewport with same size--> -1 returned
creation viewport size 205x290 . --> 4 or 5.


Well, the viewport internal is numbered but autocad don't show us the index , until he (you..) drawing inside the layout.
I think that is a bug. If I need to create a viewport outside the layout (and autocad allows this.) autocad must to number all the viewports
created. Please tell me if i wrong..
Valued Contributor
bikelink
Posts: 54
Registered: ‎11-25-2001
Message 3 of 6 (363 Views)

Re: viewport Number -1 ?

02-12-2009 03:21 AM in reply to: bikelink
isn't this...yet.

I try to make a viewport inside the layout..with height 10 in A3. It's very little viewport...and autocad return -1.

and the viewport is drawing in paper space

if the size Y-height increases 20 (example), return positive number and of course the viewport is ok.

there are a minimum size to build a viewport in paperspace ?





in my viewport buildin snapon =false..

I don't know where can i find a solution..





that's my code:

using (DocumentLock l = d.LockDocument())

{

using (Transaction t = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())

{



Point3d pt1 = new Point3d(0, 0, 0);

Point3d pt2 = new Point3d(s.X, s.Y, 0);





Viewport vport = new Viewport();

vport.Height = (double)Math.Abs(pt1.Y - pt2.Y);

vport.Width = (double)Math.Abs(pt1.X - pt2.X);

// da controllare la sottrazione dei due vettori

//Vector3d ptc = pt2.GetAsVector().Subtract(pt1.GetAsVector());

vport.CenterPoint = new Point3d(pt2.X / 2, pt2.Y / 2, 0);

vport.SetDatabaseDefaults();





BlockTable bt = (BlockTable)t.GetObject(db.BlockTableId, OpenMode.ForWrite, false);

BlockTableRecord blkRec = (BlockTableRecord)t.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForWrite, false);

blkRec.AppendEntity(vport);

vport.On = true; // can't be set until after it is added to database



vport.SnapOn = false;



vport.Color = Autodesk.AutoCAD.Colors.Color.FromColor(System.Drawing.Color.Red);

{color:#ff0000}int vpNum = vport.Number;{color}

t.AddNewlyCreatedDBObject(vport, true);

t.Commit();

viewportID = vport.ObjectId;

}

return viewportID;

}









why the number is -1 when the viewport is created with a small size in y dimension ?

the same code if i try to build a viewport with Height 20 instead of 10 return vport.number > 0
Valued Contributor
bikelink
Posts: 54
Registered: ‎11-25-2001
Message 4 of 6 (362 Views)

Re: viewport Number -1 ?

02-12-2009 05:16 AM in reply to: bikelink
OK....i don't understood ...the zoom in paper space is the base of my trouble.
if you look from distant the layout, the viewports with a little size aren't numbered!
if you perform a zoom in paper space..or better a zoom with the angle of your viewport in creation...then the number will be correct.


the right sequence is
create layout
zoom extension in paper space (but if you have an A0/A1 and some little viewport this couldn't be are enough)
better zoom on your size viewport.
creation viewport. the number is right.

thanks autocad...for this joke.. :smileyhappy:
Mentor
Rob.O
Posts: 259
Registered: ‎06-25-2007
Message 5 of 6 (197 Views)

Re: viewport Number -1 ?

01-18-2012 03:40 PM in reply to: bikelink

Excellent!

 

Sorry to bring an old thread back from the dead, but I just ran into this exact issue!

 

My newly created viewports were comining up with the number of -1.  After doing a zoom extents on the new layout (prior to creating the new viewports), the viewports are numbered properly and I no longer get an error!!

 

Thanks for figuring this out bikelink!

Active Contributor
cincir
Posts: 32
Registered: ‎08-12-2011
Message 6 of 6 (183 Views)

Re: viewport Number -1 ?

01-19-2012 11:16 AM in reply to: bikelink

İ am confused a little. arent ViewPortTableRecords member of ViewPortTable ?

Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.