Hi All,
I want to zoom the first element which is in the Level Number "3". Below is my code
Private Sub GettingElement()On Error Resume Next Dim elem As ElementDim ElemEnum As ElementEnumeratorDim elemScanCriteria As ElementScanCriteriaDim rng As Range3dDim oLevels As LevelsDim oLevel As Level Set elemScanCriteria = New ElementScanCriteria elemScanCriteria.IncludeLevel oLevel Set oLevels = ActiveDesignFile.Levels Set oLevel = oLevels.FindByNumber(3) Set ElemEnum = ActiveModelReference.Scan(elemScanCriteria) ElemEnum.MoveNext Set elem = ElemEnum.Current If elem.Level.Number = 3 Then Call SelectedElement() End If Set ElemEnum = Nothing MsgBox ("Process Completed") End Sub
Public Sub SelectedElement() Dim oEnumerator As ElementEnumerator Set oEnumerator = ActiveModelReference.GetSelectedElements Do While oEnumerator.MoveNext Dim oElement As Element Set oElement = oEnumerator.Current Const Zoom As Double = 2 Dim range As Range3d range = oElement.range Dim oView As View Set oView = ActiveDesignFile.Views.Item(1) Dim extent As Point3d extent = Point3dScale(Point3dSubtract(range.High, range.Low), Zoom) oView.Origin = Point3dSubtract(range.Low, Point3dScale(extent, 0.5)) oView.Extents = extent oView.Redraw Loop
ActiveModelReference.UnselectAllElementsEnd Sub
If I manually select any element in the dgn and runs the above, it works fine.But I want the routine to choose the element in the Level Number 3 and zoom it.
Could you please help me.
Why not using the already found Element "elem" as a prameter for the sub SelectedElement ()
like : Public Sub SelectedElement (oElementIn as Element) and work with oElementIn within the sub
oElementIn
change the: Call SelectedElement() to Call SelectedElement(elem)
and use something like that to
Public Sub ZoomAboutElement(ele As Element, dblFactor As Double, intView As Integer) Dim rng As Range3d Dim pntZoom As Point3d Dim oView As View Set oView = ActiveDesignFile.Views(intView) ' Determine the middle of the range of the element rng = ele.Range With rng pntZoom.X = .High.X - .Low.X pntZoom.Y = .High.Y - .Low.Y pntZoom.Z = .High.Z - .Low.Z pntZoom = Point3dAddScaled(rng.Low, pntZoom, 0.5) End With ' Zoom about the center of he range. Zooming does not ' update the view, so it is necessary to call oView.Redraw oView.ZoomAboutPoint pntZoom, dblFactor oView.RedrawEnd Sub
0.5
IMHO this code was already published somewhere in the forum.
BTW Do you want to zoom or select an element?
Regards
Frank
since 1985: GIS, CAD, Engineering (Civil) Senior Consultant : [Autodesk Civil 3D , Esri ArcGIS, VertiGIS: in previous days : Bentley MS V4 - V8i, GeoGraphics, Bentley Map V8i, InRoads, HHK Geograf, IBr DAVID] : Dev: [C, C++, .NET, Java, SQL, FORTRAN, UML][direct quote by: http://en.wikipedia.org/wiki/Helmut_Schmidt]: "Wer Kritik übel nimmt, hat etwas zu verbergen"Wer Grammatik- und/oder Rechtschreibfehler findet, der darf sie behalten :-)
I tried using the above zoom element function, its not working in my code.
Again if I manually select any element and run, it works fine.
But I want the code to choose the element in the Level Number 3 and zoom it.
I want to select the Level Number 3 and zoom the current element
Unknown said:I tried using the above zoom element function, its not working in my code
What do you want us to do? I'm humming the VBA mantra as I write, hoping to communicate with your code to encourage it to fix itself holistically, but it doesn't seem to be working today 8-|
If you want anyone to comment, post the code you have written so we can analyse it.
Regards, Jon Summers LA Solutions
Hi Bentley1,
here you are: gist.github.com/.../d50d9760c023d7a90eb1
It is untested code.
Answer Verified By: Azarudeen Liyakath Ali