2014-09-12 6 views
2

VBA 스크립팅을 사용하여 Autodesk Inventor에서 두 개의 솔리드 모델 프로파일을 연결하려고합니다. 나중에 프로파일로 작동해야하는 3D 선을 그리는 데까지 이르렀습니다. 스크립트 작성이 끝나면 두 개의 루프를 선택하고 GUI를 통해 로프트 작업을 사용하여 연결합니다. 나는 스크립트에서 가능해야한다고 생각하고있다. 나는 방법을 알 수 없다. 여기 내 스크립트는 지금까지의 :Autodesk Inventor VBA 스크립팅

Sub loft() 

    Set oDoc = ThisApplication.Documents.Add(kPartDocumentObject, , True) 
    Set oPartDef = oDoc.ComponentDefinition 

    Dim osketch3D As Sketch3D 
    Set osketch3D = oPartDef.Sketches3D.Add() 

    Set oTG = ThisApplication.TransientGeometry 
    Dim wire(198) As SketchLine3D 

    Set wire(0) = osketch3D.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(0, 0, 0), oTG.CreatePoint(10, 0, 0)) 
    Set wire(1) = osketch3D.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(10, 0, 0), oTG.CreatePoint(10, 10, 1)) 
    Set wire(2) = osketch3D.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(10, 10, 1), oTG.CreatePoint(0, 10, 0)) 
    Set wire(3) = osketch3D.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(0, 10, 0), oTG.CreatePoint(0, 0, 0)) 

    Set wire(4) = osketch3D.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(0, 0, 5), oTG.CreatePoint(10, 0, 5)) 
    Set wire(5) = osketch3D.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(10, 0, 5), oTG.CreatePoint(10, 10, 5)) 
    Set wire(6) = osketch3D.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(10, 10, 5), oTG.CreatePoint(0, 10, 5)) 
    Set wire(7) = osketch3D.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(0, 10, 5), oTG.CreatePoint(0, 0, 5)) 

' .....  
' Select wires 0-3 and 4-7 as profiles, put them in an object collection and call the loft op. 

End Sub 

답변

1
Sub loft() 

    'Declare PartDocument to activate Intellisense 
    Dim oDoc As PartDocument 

    Set oDoc = ThisApplication.Documents.Add(kPartDocumentObject, , True) 
    Set oPartDef = oDoc.ComponentDefinition 

    Dim osketch3D As Sketch3D 
    Set osketch3D = oPartDef.Sketches3D.Add() 

    Set oTG = ThisApplication.TransientGeometry 
    Dim wire(198) As SketchLine3D 

    Set wire(0) = osketch3D.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(0, 0, 0), oTG.CreatePoint(10, 0, 0)) 
    Set wire(1) = osketch3D.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(10, 0, 0), oTG.CreatePoint(10, 10, 1)) 
    Set wire(2) = osketch3D.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(10, 10, 1), oTG.CreatePoint(0, 10, 0)) 
    Set wire(3) = osketch3D.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(0, 10, 0), oTG.CreatePoint(0, 0, 0)) 

    'Declare Profile3D to regroup wires. 
    Dim oProfile1 As Profile3D 
    Set oProfile1 = osketch3D.Profiles3D.AddOpen 

    'Declare another sketch to be able to catch 2 differents profiles. 
    Dim osketch3D2 As Sketch3D 
    Set osketch3D2 = oPartDef.Sketches3D.Add() 

    Set wire(4) = osketch3D2.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(0, 0, 5), oTG.CreatePoint(10, 0, 5)) 
    Set wire(5) = osketch3D2.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(10, 0, 5), oTG.CreatePoint(10, 10, 5)) 
    Set wire(6) = osketch3D2.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(10, 10, 5), oTG.CreatePoint(0, 10, 5)) 
    Set wire(7) = osketch3D2.SketchLines3D().AddByTwoPoints(oTG.CreatePoint(0, 10, 5), oTG.CreatePoint(0, 0, 5)) 

    'Declare second Profile3D to regroup wires. 
    Dim oProfile2 As Profile3D 
    Set oProfile2 = osketch3D2.Profiles3D.AddOpen 

    'Create object collection need by Inventor functions. 
    Dim oCollection As ObjectCollection 
    Set oCollection = ThisApplication.TransientObjects.CreateObjectCollection 

    'Add profiles to collection. 
    oCollection.Add oProfile1 
    oCollection.Add oProfile2 

    'Create loft definition needed by Loft function. 
    Dim oLoftDef As LoftDefinition 
    Set oLoftDef = oDoc.ComponentDefinition.Features.LoftFeatures.CreateLoftDefinition(oCollection, kSurfaceOperation) 

    'Creating loft. 
    Dim oLoftFeat As LoftFeature 
    Set oLoftFeat = oDoc.ComponentDefinition.Features.LoftFeatures.Add(oLoftDef) 



End Sub 
+0

당신은 변경되는 코드의 부분을 언급하고 문제를 해결 이유를 언급해야한다. –

+1

나는 그것이 일들을 명확히 할 수 있다고 생각하지만,이 해결책은 매우 간단해서 나는 코멘트를위한 장소가 있다고 믿지 않았다. 당신이 지적 했으므로 이제는 대답을 수정하겠습니다. –