Hi
I have a problem with making a locate while running through a feature enumerator from a previos made scan, PowerMap crashes when going to the second item in the outer loop.
I have made this very simple application to show the problem (The application ans a test designfile is attached in a zip)
********* Main appication ***************Attribute VB_Name = "modLocateTest"Public ScanFeatureEnumerator As xft.FeatureEnumeratorPublic ScanFeatureCount As LongPublic XpathFeatureEnumerator As xft.FeatureEnumeratorPublic XpathFeatureCount As LongPublic Function GetFeaturesByXpathAndPoint(ByVal Xpath As String, Pkt As Point3d, ByVal SnapDist As Double) As Integer'--------------------------------------------------------------------' Function makes a XpathScan near Point Pkt ' Found features are in enumaerat XpathFeatureEnumerator' Function returns number of found features'---------------------------------------------------------------------Dim oLocateOp As New xft.locateOpDim oPoint As New xft.InputPointDim toleranceValue As New InputValuetoleranceValue.SetTypeAndValue ValueType_VALUE, Str(SnapDist)oLocateOp.Tolerance = toleranceValueoPoint.SetLocation Pkt.X, Pkt.Y, Pkt.Z, FalseoLocateOp.ScanAtPoint = TrueoLocateOp.ReferencePoint = oPointoLocateOp.Mode = LocateOpMode.locateOpModeScanoLocateOp.Xpath = XpathoLocateOp.AutoAcceptScanFile = TrueCmdMgr.StartLocateOperation oLocateOp, New clsLocateXpathGetFeaturesByNameAndPoint = XpathFeatureCountEnd FunctionPublic Function ScanFeaturesByName(ByVal FeatureNames As String) As Integer'--------------------------------------------------------------------' Function makes a Scan for the comma delimited featurenames ' Founf features are in enumarator ScanFeatureEnumerator' Function returns number of found features'---------------------------------------------------------------------Dim oLocateOp As New xft.locateOpDim Features() As StringDim i As IntegeroLocateOp.Mode = LocateOpMode.locateOpModeScanIf Trim(FeatureNames) <> "" Then Features() = Split(FeatureNames, ",") For i = 0 To UBound(Features) oLocateOp.IncludeFeatureName Features(i) NextEnd IfoLocateOp.AutoAcceptScanFile = TrueCmdMgr.StartLocateOperation oLocateOp, New clsScanLocateScanFeaturesByName = ScanFeatureCountEnd FunctionPublic Sub main()Dim oFeature As xft.featureDim Pkt As point3dIf ScanFeaturesByName("Brønd,TilslutningKn,FiktivKnude,DelLednKnude,AndenKnude") > 0 Then Do While ScanFeatureEnumerator.MoveNext Set oFeature = ScanFeatureEnumerator.Current 'MsgBox oFeature.GetXml Pkt.X = oFeature.Geometry.AsCellElement.Origin.X Pkt.Y = oFeature.Geometry.AsCellElement.Origin.Y Pkt.Z = oFeature.Geometry.AsCellElement.Origin.Z If GetFeaturesByXpathAndPoint("Dæksel", Pkt, 5#) > 0 Then Do While XpathFeatureEnumerator.MoveNext Set oFeature = XpathFeatureEnumerator.Current MsgBox oFeature.GetXml Loop End If LoopEnd IfEnd Sub********************************************************************** Two LocateOp clasees *****************VERSION 1.0 CLASSBEGIN MultiUse = -1 'TrueENDAttribute VB_Name = "clsScanLocate"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = FalseAttribute VB_Exposed = FalseImplements ILocateOpEvents Private Sub ILocateOpEvents_OnCleanup()End SubPrivate Sub ILocateOpEvents_OnFinished(ByVal locateOp As xft.ILocateOp)modLocateTest.ScanFeatureCount = locateOp.LocatedFeaturesCountSet modLocateTest.ScanFeatureEnumerator = locateOp.GetLocatedFeatures End SubPrivate Sub ILocateOpEvents_OnRejected(ByVal RejectedReasonType As xft.LocateOpRejectedReasonType, RejectedReason As String)End SubPrivate Sub ILocateOpEvents_OnTerminate()End SubPrivate Sub ILocateOpEvents_OnValidate(ByVal RootFeature As xft.IFeature, ByVal element As element, Point As Point3d, ByVal View As View, Accepted As Boolean, RejectReason As String)Accepted = TrueEnd Sub*********************************************************VERSION 1.0 CLASSBEGIN MultiUse = -1 'TrueENDAttribute VB_Name = "clsLocateXpath"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = FalseAttribute VB_Exposed = FalseImplements ILocateOpEvents Private Sub ILocateOpEvents_OnCleanup()End SubPrivate Sub ILocateOpEvents_OnFinished(ByVal locateOp As xft.ILocateOp)modLocateTest.XpathFeatureCount = locateOp.LocatedFeaturesCountSet modLocateTest.XpathFeatureEnumerator = locateOp.GetLocatedFeatures End SubPrivate Sub ILocateOpEvents_OnRejected(ByVal RejectedReasonType As xft.LocateOpRejectedReasonType, RejectedReason As String)End SubPrivate Sub ILocateOpEvents_OnTerminate()End SubPrivate Sub ILocateOpEvents_OnValidate(ByVal RootFeature As xft.IFeature, ByVal element As element, Point As Point3d, ByVal View As View, Accepted As Boolean, RejectReason As String)Accepted = TrueEnd SubThanks in advance
Erik Wirring
Hi. It is currently not supported to use the result of a locate operation directly within another locate operation (nesting). Even though you are storing the pointers to the iterators separately, internally this doesn't work. The construction of the second locate operator destroys the list owned by the first.
For now I suggest that you first iterate on the results of your first iterator and store the list of result features in your application, and as a second step work with that local list for your second locate operation.
Hope this helps,
Martin
Hi Martin
Thanks for the help. I have change the routines so they saves the found features in features arrays instead. It works fine, I was some unsure whether I would be able to update the features, but that seems to work too.
Erik