Hellow Everyone,
I have a problem geting information if a polyline is higer then the layout size using autocad 2008 vba
The picture below shows what i mean
Please Help
Thankyou very much
Hi,
I would first verify the extents of the rectangle and the polyline, and in a seconed step (if necessary) check vertex-by-vertex of the polyline if it's within the rectangle or outside the rectangle.
- alfred -
Froom your previous post, it looks like you want to get the portion of a polyline in modelspace that can bee seen through a paperspace viewport.
Because the view in paperspace viewport can be scaled, twisted, you need to project the viewport border into modelspace to actually know the intersection points the polyline with the viewport border (in modelspace), then you can proceed to find the portion(s) of polyline seeable through the paperspace viewport.
So, your code need to do these:
1. select a paperspace viewport in interest;
2. find the viewport's size (width, height). Things can get complicated if the viewport is clipped with a non-rectangular shape. You may want to work with rectangular viewport as starter;
3. translate coordinates of 4 corners of the viewport into modelspace coordinates. so you can construct a rectangle polygon in modelspace, representing the modelspace area that can be seen through the paperspace viewport; You use AcadUtility.TranslateCoordinate() to translate the coordinates;
4. Now you can use IntesectWith(0 to get points where the polyline and the rectangle meets;
5. According to the intersection points, you search through the vertices of the polygon one by one to determine which portion of the polyline is inside the rectangle.
Following code shows an sample from step 1 to 3. You should be able to work out the rest, based on previous code I showed:
Option Explicit Public Sub DrawVPortInModelSpace() ''Make sure it is in paperspace If ThisDrawing.ActiveSpace <> acPaperSpace Then MsgBox "Not in PaperSpace!", vbCritical Exit Sub End If ThisDrawing.MSpace = False ''Pick the view port polygon Dim ent As AcadEntity Dim pt As Variant On Error Resume Next ThisDrawing.Utility.GetEntity _ ent, pt, vbCr & "Pick a viewprot border:" If ent Is Nothing Then Exit Sub On Error GoTo 0 Dim vPort As AcadPViewport If TypeOf ent Is AcadPViewport Then Set vPort = ent DrawVPortInModel vPort End If End Sub Private Sub DrawVPortInModel(vPort As AcadPViewport) Dim vCentre As Variant Dim dWHalf As Double Dim dHHalf As Double Dim dScale As Double vCentre = vPort.Center dWHalf = vPort.Width / 2# dHHalf = vPort.Height / 2# dScale = 1 / vPort.CustomScale ThisDrawing.MSpace = True ThisDrawing.ActivePViewport = vPort Dim mCentre As Variant mCentre = ThisDrawing.Utility.TranslateCoordinates( _ vCentre, acPaperSpaceDCS, acDisplayDCS, 0) mCentre = ThisDrawing.Utility.TranslateCoordinates( _ mCentre, acDisplayDCS, acWorld, 0) '' Calculate polygon's lower-left corner and '' upper-right corner in modelspace Dim llCorner(0 To 2) As Double Dim urCorner(0 To 2) As Double llCorner(0) = mCentre(0) - (dWHalf * dScale) llCorner(1) = mCentre(1) - (dHHalf * dScale) llCorner(2) = 0# urCorner(0) = mCentre(0) + (dWHalf * dScale) urCorner(1) = mCentre(1) + (dHHalf * dScale) urCorner(2) = 0# DrawPolygonInModel llCorner, urCorner End Sub Private Sub DrawPolygonInModel(llCorner As Variant, urCorner As Variant) Dim polygon As AcadLWPolyline Dim coords(0 To 7) As Double ''Lower-left coords(0) = llCorner(0) coords(1) = llCorner(1) ''lower-right coords(2) = urCorner(0) coords(3) = llCorner(1) ''upper-right coords(4) = urCorner(0) coords(5) = urCorner(1) ''upper-left coords(6) = llCorner(0) coords(7) = urCorner(1) Set polygon = ThisDrawing.ModelSpace.AddLightWeightPolyline(coords) polygon.Closed = True polygon.Update End Sub
Norman Yuan
Thankyou again for your help and Repplys
Couldn't done without your help
So Thankyou so much 🙂