cancel
Showing results for 
Search instead for 
Did you mean: 

Dim feature4 As NXOpen.CAM.FBM.Feature = CType(workPart.FindObject("ENTITY 111 1 1"), NXOpen.CAM.FBM

Pioneer
Pioneer

I have recorded a journal to edit drilling operation which is created using hole_making template; part of the step is to change the "Depth" value.

When replay, the following error come up: Unable to cast object of type 'NXOpen.NXObject' to type 'NXOpen.CAM.FBM.Feature'.

The problem comes from this line:

Dim feature4 As NXOpen.CAM.FBM.Feature = CType(workPart.FindObject("ENTITY 111 1 1"), NXOpen.CAM.FBM.

I think the problem is this "ENTITY 111 1 1".

Is there any other way to accomplish the same function?

Thanks.

 

Below is the code:

Module NXJournal
    Sub Main(ByVal args() As String)

        Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
        Dim workPart As NXOpen.Part = theSession.Parts.Work

        Dim displayPart As NXOpen.Part = theSession.Parts.Display

        Dim holeDrilling1 As NXOpen.CAM.HoleDrilling = CType(workPart.CAMSetup.CAMOperationCollection.FindObject("DRILLING"), NXOpen.CAM.HoleDrilling)

        theSession.CAMSession.PathDisplay.ShowToolPath(holeDrilling1)

        theSession.CAMSession.PathDisplay.HideToolPath(holeDrilling1)

        Dim markId1 As NXOpen.Session.UndoMarkId
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Edit DRILLING")

        Dim markId2 As NXOpen.Session.UndoMarkId
        markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")

        Dim holeDrillingBuilder1 As NXOpen.CAM.HoleDrillingBuilder
        holeDrillingBuilder1 = workPart.CAMSetup.CAMOperationCollection.CreateHoleDrillingBuilder(holeDrilling1)

        Dim holeMachiningCutParameters1 As NXOpen.CAM.HoleMachiningCutParameters
        holeMachiningCutParameters1 = holeDrillingBuilder1.CuttingParameters

        theSession.SetUndoMarkName(markId2, "Drilling - [DRILLING] Dialog")

        Dim markId3 As NXOpen.Session.UndoMarkId
        markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")

        Dim featureGeometry1 As NXOpen.CAM.FBM.FeatureGeometry
        featureGeometry1 = holeDrillingBuilder1.GetFeatureGeometry()

        Dim machiningFeatureGeometry1 As NXOpen.CAM.FBM.MachiningFeatureGeometry = CType(featureGeometry1, NXOpen.CAM.FBM.MachiningFeatureGeometry)

        Dim geometrySetList1 As NXOpen.CAM.GeometrySetList
        geometrySetList1 = machiningFeatureGeometry1.GeometryList

        theSession.SetUndoMarkName(markId3, "Feature Geometry Dialog")

        Dim taggedObject1 As NXOpen.TaggedObject
        taggedObject1 = geometrySetList1.FindItem(0)

        Dim featureSet1 As NXOpen.CAM.FBM.FeatureSet = CType(taggedObject1, NXOpen.CAM.FBM.FeatureSet)

        ' ----------------------------------------------
        '   Dialog Begin Feature Geometry
        ' ----------------------------------------------
        Dim feature1 As NXOpen.CAM.FBM.Feature = CType(workPart.FindObject("ENTITY 111 2 1"), NXOpen.CAM.FBM.Feature)

        Dim cAMAttribute1 As NXOpen.CAM.CAMAttribute
        cAMAttribute1 = feature1.GetAttribute("DEPTH")

        cAMAttribute1.SetDoubleValue(17.95707)

        theSession.UpdateManager.LogForUpdate(feature1)

        Dim featureSet2 As NXOpen.CAM.FBM.FeatureSet
        featureSet2 = machiningFeatureGeometry1.GetFeatureSet(0)

        Dim feature2 As NXOpen.CAM.FBM.Feature
        feature2 = featureSet2.GetFeature()

        feature2.OverrideAttributeValue("DEPTH", 17.95707)

        Dim id1 As NXOpen.Session.UndoMarkId
        id1 = theSession.NewestVisibleUndoMark

        Dim nErrs1 As Integer
        nErrs1 = theSession.UpdateManager.DoUpdate(id1)

        Dim id2 As NXOpen.Session.UndoMarkId
        id2 = theSession.NewestVisibleUndoMark

        Dim nErrs2 As Integer
        nErrs2 = theSession.UpdateManager.DoUpdate(id2)

        Dim markId4 As NXOpen.Session.UndoMarkId
        markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Feature Geometry")

        Dim cAMAttribute2 As NXOpen.CAM.CAMAttribute
        cAMAttribute2 = feature2.GetAttribute("DEPTH")

        cAMAttribute2.SetDoubleValue(30.0)

        theSession.UpdateManager.LogForUpdate(feature2)

        Dim featureSet3 As NXOpen.CAM.FBM.FeatureSet
        featureSet3 = machiningFeatureGeometry1.GetFeatureSet(0)

        Dim feature3 As NXOpen.CAM.FBM.Feature
        feature3 = featureSet3.GetFeature()

        feature3.OverrideAttributeValue("DEPTH", 30.0)

        Dim id3 As NXOpen.Session.UndoMarkId
        id3 = theSession.NewestVisibleUndoMark

        Dim nErrs3 As Integer
        nErrs3 = theSession.UpdateManager.DoUpdate(id3)

        Dim id4 As NXOpen.Session.UndoMarkId
        id4 = theSession.NewestVisibleUndoMark

        Dim nErrs4 As Integer
        nErrs4 = theSession.UpdateManager.DoUpdate(id4)

        theSession.DeleteUndoMark(markId4, Nothing)

        Dim markId5 As NXOpen.Session.UndoMarkId
        markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Feature Geometry")

        theSession.DeleteUndoMark(markId5, Nothing)

        theSession.SetUndoMarkName(markId3, "Feature Geometry")

        theSession.DeleteUndoMark(markId3, Nothing)

        Dim markId6 As NXOpen.Session.UndoMarkId
        markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Drilling - [DRILLING]")

        theSession.DeleteUndoMark(markId6, Nothing)

        Dim markId7 As NXOpen.Session.UndoMarkId
        markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Drilling - [DRILLING]")

        Dim nXObject1 As NXOpen.NXObject
        nXObject1 = holeDrillingBuilder1.Commit()

        theSession.DeleteUndoMark(markId7, Nothing)

        theSession.SetUndoMarkName(markId2, "Drilling - [DRILLING]")

        holeDrillingBuilder1.Destroy()

        theSession.DeleteUndoMark(markId2, Nothing)

        ' ----------------------------------------------
        '   Menu: Tools->Journal->Stop Recording
        ' ----------------------------------------------

    End Sub
End Module
NX 10.0.3.5, WINDOWS 7
5 REPLIES

Re: Dim feature4 As NXOpen.CAM.FBM.Feature = CType(workPart.FindObject("ENTITY 111 1 1"),

Esteemed Contributor
Esteemed Contributor

Recorded journals need to be generalized to be usable in any situation.

Every FindObject method needs to be replaced with another way to select the object.

There is a topic about this in the NX documentation in the section NXOpen programming.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX12.0

How to Get the Most from Your Signature in the Community

Re: Dim feature4 As NXOpen.CAM.FBM.Feature = CType(workPart.FindObject("ENTITY 111 1 1"),

Pioneer
Pioneer
thanks for the prompt reply; but..
Can you be more specific on which topic?
Thanks again
NX 10.0.3.5, WINDOWS 7

Re: Dim feature4 As NXOpen.CAM.FBM.Feature = CType(workPart.FindObject("ENTITY 111 1 1"),

Esteemed Contributor
Esteemed Contributor

See Turning journals into applications

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX12.0

How to Get the Most from Your Signature in the Community

Re: Dim feature4 As NXOpen.CAM.FBM.Feature = CType(workPart.FindObject("ENTITY 111 1 1"),

Pioneer
Pioneer

Thanks again.

NX 10.0.3.5, WINDOWS 7

Re: Dim feature4 As NXOpen.CAM.FBM.Feature = CType(workPart.FindObject("ENTITY 111 1 1"),

Pioneer
Pioneer
Hi,
I'm not sure, but it worked after replace the line with these lines of codes:

Dim feature4 As NXOpen.CAM.FBM.Feature
feature4 = featureSet4.GetFeature()

Thanks again
NX 10.0.3.5, WINDOWS 7