iCAx开思工具箱

标题: 请教vb.net下UG二次开发:拉伸特征方位变换(有源码) [打印本页]

作者: neighbornet    时间: 2007-3-27 14:09
标题: 请教vb.net下UG二次开发:拉伸特征方位变换(有源码)
总是变换不成功,弹出错误对话框,

请高人指点,多谢!!!



' NX 4.0.0.25
' Journal created by nmgf on Tue Mar 27 11:12:31 2007 中国标准时间
'
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module UGTransformTest
    Sub Main()

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

        Dim displayPart As Part = theSession.Parts.Display

        ' ----------------------------------------------
        '  菜单: 插入->曲线->Basic Curves...
        ' ----------------------------------------------
        
        Dim startPoint1 As Point3d = New Point3d(-30, 30, 0.0)
        Dim endPoint1 As Point3d = New Point3d(60, 30, 0.0)
        Dim line1 As Line
        line1 = workPart.Curves.CreateLine(startPoint1, endPoint1)

        
        Dim startPoint2 As Point3d = New Point3d(60, 30, 0.0)
        Dim endPoint2 As Point3d = New Point3d(60, -30, 0.0)
        Dim line2 As Line
        line2 = workPart.Curves.CreateLine(startPoint2, endPoint2)

        
        Dim startPoint3 As Point3d = New Point3d(60, -30, 0.0)
        Dim endPoint3 As Point3d = New Point3d(-30, -30, 0.0)
        Dim line3 As Line
        line3 = workPart.Curves.CreateLine(startPoint3, endPoint3)

     

        Dim startPoint4 As Point3d = New Point3d(-30, -30, 0.0)
        Dim endPoint4 As Point3d = New Point3d(-30, 30, 0.0)
        Dim line4 As Line
        line4 = workPart.Curves.CreateLine(startPoint4, endPoint4)

        

        ' ----------------------------------------------
        '  菜单: 插入->Design Feature->拉伸...
        ' ----------------------------------------------
        

        Dim section1 As Section
        section1 = workPart.Sections.CreateSection(0.02413, 0.0254, 0.5)

        Dim nullFeatures_Feature As Features.Feature = Nothing

        Dim extrudeBuilder1 As Features.ExtrudeBuilder
        extrudeBuilder1 = workPart.Features.CreateExtrudeBuilder(nullFeatures_Feature)

        extrudeBuilder1.Section = section1

        Dim limits1 As GeometricUtilities.Limits
        limits1 = extrudeBuilder1.Limits

        Dim featureOptions1 As GeometricUtilities.FeatureOptions
        featureOptions1 = extrudeBuilder1.FeatureOptions

        Dim linearLimits1 As GeometricUtilities.LinearLimits = CType(limits1, GeometricUtilities.LinearLimits)

        Dim extend1 As GeometricUtilities.Extend
        extend1 = linearLimits1.StartExtend

        Dim extend2 As GeometricUtilities.Extend
        extend2 = linearLimits1.EndExtend

        Dim booleanOperation1 As GeometricUtilities.BooleanOperation
        booleanOperation1 = extrudeBuilder1.BooleanOperation

        Dim direction1 As Direction
        direction1 = extrudeBuilder1.Direction

        Dim featureOffset1 As GeometricUtilities.FeatureOffset
        featureOffset1 = extrudeBuilder1.Offset

        Dim simpleDraft1 As GeometricUtilities.SimpleDraft
        simpleDraft1 = extrudeBuilder1.Draft

        Dim featureOptions2 As GeometricUtilities.FeatureOptions
        featureOptions2 = extrudeBuilder1.FeatureOptions

        extend1.SetValue("0")

        extend2.SetValue("25")

        featureOffset1.SetStartOffset("0")

        featureOffset1.SetEndOffset("5")

        featureOffset1.OffsetType = GeometricUtilities.Type.NonsymmetricOffset

        simpleDraft1.SetDraftAngle("2")

        simpleDraft1.DraftType = GeometricUtilities.SimpleDraft.SimpleDraftType.SimpleFromStart


        Dim curves1(3) As Curve
        curves1(0) = line3
        curves1(1) = line2
        curves1(2) = line1
        curves1(3) = line4
        Dim curveDumbRule1 As CurveDumbRule
        curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumb(curves1)

        section1.AllowSelfIntersection(False)

        Dim rules1(0) As SelectionIntentRule
        rules1(0) = curveDumbRule1
        Dim nullNXObject As NXObject = Nothing

        Dim helpPoint1 As Point3d = New Point3d(33.1834217214209, -32.8259757986841, 0.0)
        section1.AddToSection(rules1, line3, nullNXObject, nullNXObject, helpPoint1, Section.Mode.Create)


        Dim origin1 As Point3d = New Point3d(11.40625, -7.96875000000001, 0.0)
        Dim vector1 As Vector3d = New Vector3d(0.0, 0.0, 1.0)
        Dim direction2 As Direction
        direction2 = workPart.Directions.CreateDirection(origin1, vector1, SmartObject.UpdateOption.WithinModeling)

        extrudeBuilder1.Direction = direction2

      
        Dim feature1 As Features.Feature
        feature1 = extrudeBuilder1.CommitFeature()

        extrudeBuilder1.Destroy()

        ' ----------------------------------------------
        '  菜单: 工具->日记->停止
        ' ----------------------------------------------

        Dim fs() As Features.Feature = workPart.Features.ToArray

        Dim count As Integer = fs.GetLength(0)
        Dim i As Integer = 0

        Dim featureTag(count - 1) As Tag

        For Each f As Features.Feature In fs
            featureTag(i) = f.Tag
            i += 1

        Next
        
        Dim transMode As Integer = 2

        Dim csysTrans(1, 11) As Double

        csysTrans(0, 0) = 0
        csysTrans(0, 1) = 0
        csysTrans(0, 2) = 0

        csysTrans(0, 3) = 1
        csysTrans(0, 4) = 0
        csysTrans(0, 5) = 0
        csysTrans(0, 6) = 0
        csysTrans(0, 7) = 1
        csysTrans(0, 8) = 0
        csysTrans(0, 9) = 0
        csysTrans(0, 10) = 0
        csysTrans(0, 11) = 1



        csysTrans(1, 0) = 120
        csysTrans(1, 1) = 0
        csysTrans(1, 2) = 0


        csysTrans(1, 3) = 0
        csysTrans(1, 4) = 0
        csysTrans(1, 5) = 1
        csysTrans(1, 6) = 1
        csysTrans(1, 7) = 0
        csysTrans(1, 8) = 0
        csysTrans(1, 9) = 0
        csysTrans(1, 10) = 1
        csysTrans(1, 11) = 0

        Dim theUFSession As UFSession = UFSession.GetUFSession
        theUFSession.Modl.MoveFeature(featureTag, transMode, csysTrans)

        theUFSession.Modl.Update()
    End Sub
End Module
作者: neighbornet    时间: 2007-3-28 15:15
标题: re:
(附源码)
我用block特征测试了一下,完全能够变换,没有出现任何错误
所以我认为可能是拉伸特征是从曲线拉伸的原因,因为拉伸体是曲线的子特征,所以应该变换那些曲线特征!
可是,如何得到那些曲线特征呢?我只能用CreateLine得到Line对象,有没有办法得到拉伸体的曲线特征呢 ?
多谢

请高人指点~~~~~~

对了,我用的是UG NX4, VB.NET




Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF



Module Transform

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUFSession As UFSession = UFSession.GetUFSession

        Dim workPart As Part = theSession.Parts.Work
        Dim displayPart As Part = theSession.Parts.Display


        Dim nullFeatures_Feature As Features.Feature = Nothing

        Dim blockFeatureBuilder1 As Features.BlockFeatureBuilder
        blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature)

        Dim basePoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)

        blockFeatureBuilder1.SetOriginAndLengths(basePoint1, "100", "80", "10")

        Dim nullBody As Body = Nothing

        blockFeatureBuilder1.SetBooleanOperationAndTarget(Features.Feature.BooleanType.Create, nullBody)

        Dim feature1 As Features.Feature
        feature1 = blockFeatureBuilder1.CommitFeature()

        blockFeatureBuilder1.Destroy()



        Dim theBodies() As Body = workPart.Bodies.ToArray
        Dim theFeatures() As Features.Feature = theBodies(0).GetFeatures


        Dim bodyTag(0) As Tag
        bodyTag(0) = theFeatures(0).Tag



        Dim transMode As Integer = 2

        Dim csysTrans(1, 11) As Double

        csysTrans(0, 0) = 0
        csysTrans(0, 1) = 0
        csysTrans(0, 2) = 0

        csysTrans(0, 3) = 1
        csysTrans(0, 4) = 0
        csysTrans(0, 5) = 0
        csysTrans(0, 6) = 0
        csysTrans(0, 7) = 1
        csysTrans(0, 8) = 0
        csysTrans(0, 9) = 0
        csysTrans(0, 10) = 0
        csysTrans(0, 11) = 1



        csysTrans(1, 0) = 120
        csysTrans(1, 1) = 0
        csysTrans(1, 2) = 0


        csysTrans(1, 3) = 0
        csysTrans(1, 4) = 0
        csysTrans(1, 5) = 1
        csysTrans(1, 6) = 1
        csysTrans(1, 7) = 0
        csysTrans(1, 8) = 0
        csysTrans(1, 9) = 0
        csysTrans(1, 10) = 1
        csysTrans(1, 11) = 0

        theUFSession.Modl.MoveFeature(bodyTag, transMode, csysTrans)

        theUFSession.Modl.Update()
    End Sub

End Module
作者: neighbornet    时间: 2007-3-31 13:07
提前~~,让高人看到~~
作者: neighbornet    时间: 2007-4-13 10:48
高手都不来了吗?遗憾~~
作者: kelleyz    时间: 2007-6-20 02:31
vb也可以做吗
可不可以告诉我要什么插件




欢迎光临 iCAx开思工具箱 (https://t.icax.org/) Powered by Discuz! X3.3