Hi,
The little hair I have left is turning grey in frustration.
I am running MicroStation V8i and try to automate some procedures.
I am trying to perform a partialdelete function on an arc, but the function returns "Nothing" in the return element.
For testing I created an arc running through (5,5,0) just to make things easy
The routine is part of a much larger program that draws Coplex Chains from different elements, but this little bit is not working.
Anyone seeing something I can't see?
Sub PartDel() Dim scancrit As ElementScanCriteria Dim elemenum As ElementEnumerator Dim point(2) As Point3d Dim elm1 As Element Dim elm2 As Element Dim archelem As Element Dim dist As Double point(0).x = 0 point(0).Y = 0 point(0).Z = 0 Set scancrit = New ElementScanCriteria scancrit.ExcludeNonGraphical scancrit.IncludeType msdElementTypeArc Set elemenum = ActiveModelReference.Scan(scancrit) Do While elemenum.MoveNext Set archelem = elemenum.current point(1) = archelem.AsArcElement.StartPoint point(2).x = 5 ' this is a known point (variable) point(2).Y = 5 ' It shall be part of the parameters point(2).Z = 0 ' to this routine archelem.AsArcElement.PartialDelete elm1, elm2, point(1), point(2), point(0), 1 ' This return "Nothing" in elm1 ActiveModelReference.AddElement elm1 Loop End Sub
It's very messy, mixing up your scan logic with the partial delete logic.
Prefer to write a function that has a single purpose. In this example, write a function that performs the partial delete, and pass the parameters from your scan. Something like this (untested) code...
Function PartialDelete ( _ ByVal oArc As ArcElement, _ ByRef point1 As Point3d, _ ByRef point2 As Point3d, _ ByRef point3 As Point3d, _ ByVal nView As Integer) As Element Dim oResult1 As Element Dim oResult2 As Element oArc.PartialDelete oResult1, oResult2, point1, point2, point3, nView Set PartialDelete = oResult1 End Function
Regards, Jon Summers LA Solutions
Answer Verified By: Finn Mejding
You're right Jon
I changed it to a function, and now it works.
Only exception from your code sample, is that it return the partial deleted element in oResult2.
But a simple test do the trick.
Thanks.
Regards,
Finn Mejding
CAD Manager
Railway and Metro
COWI
Finn Mejding said:I changed it to a function, and now it works
Excellent! It's funny how refactoring (I changed it to a function, and now it works) obliges us to re-examine our logic and spot previously unnoticed errors.
Yes, we sometimes go blind for other solutionss, until someone ask questions