Pages

Showing posts with label VBA. Show all posts
Showing posts with label VBA. Show all posts

Monday, June 11, 2012

Kinect Hack Video: CATIA V5 Manipulation


KinectCAD for CATIA V5

I recently stumbled upon one of the coolest Kinect applications I’ve ever seen. The Kinect is Microsoft’s Xbox 360’s latest webcam style peripheral. This new high tech toy permits users to “be the controller” through natural user interface (NUI) by controlling the game with their voice and body movements. Microsoft took it a step further and released the Kinect software development kit (SDK) for Windows 7 allowing developers to write Kinect applications in C++, C#, or Visual Basic .NET. There are numerous “Kinect hacking” videos on YouTube. One such user has now manipulated the Kinect to provide a gesture based movement of CATIA part objects.




How to use Kinect with CATIA V5? Using this new application in development it is now possible to rotate and zoom in or out of your new Kinect 3D CAD model while standing in front of your monitor and using your arms. It gets even better: utilizing Kinect’s built in microphone there is a rudimentary speech recognition function you can use to change the rotation axes. Can you imagine creating every part in CATIA this way (or any other CAD system for that matter)?

Using the SDK V1 software for Kinect, KinectCAD has been created in Visual C# 2010. It may be a slow way to work (at first) but is a brilliant concept nonetheless. Pretty soon we’ll be seeing 3d Kinect models of all our CAD parts. It would be a great way for automakers to perform layout check in conference rooms (and funny to watch  too). Hats off to the creators and I can’t wait to see more. Checkout the Kinect video recording below:


Please note: this program is still in development.  To learn more please visit this site. So, what do you think of KinectCAD? What other applications could you see between Xbox Kinect and CATIA V5? Please leave a comment below!

Saturday, December 3, 2011

Gift Ideas for CAD and 3D Modelers

Are you shopping for a CAD user, 3D modeler, or an engineer? Well, I have a couple of holiday gift suggestions for you.

A full-color guide to the #1 architectural drafting program—AutoCAD 2012 for Dummies. AutoCAD is the leading software used to create 2D and 3D technical drawings. Used by engineers, architects, and drafting professionals, it can be complex and is a perfect subject for the tried-and-true For Dummies format. Full-color illustrations make the instructions even easier to follow, because examples in the book appear exactly as they will on the screen.


Fully updated for the latest version of software, Kelley’s Pro/ENGINEER Wildfire 5.0 Instructor remains organized around step-by-step tutorials — the most effective way to teach and learn this procedure-intensive CAD application. Pro/ENGINEER Wildfire 5.0 Instructor provides a solid background in parametric design and constraint-based modeling. In addition, the comprehensive references make this text an all-in-one tutorial, reference, and lecture guide for students of Pro/ENGINEER.


CATIA V6 (Computer-Aided Three Dimensional Interactive Application) is the world's leading multi-platform CAD/CAM/CAE software suite marketed worldwide by IBM. It allows the user to apply its capabilities to a variety of industries such as automotive, industrial robots, electronics, manufacturing design, aerospace, and consumer goods. CATIA V6 Essentials includes all the major concepts related to the latest version of CATIA, such as installation, modes, and modeling in an easy-to-understand, step-by-step format. It also covers all the major commands and techniques and provides the reader with all of the details to learn the basics with a clear method of instruction. This comprehensive reference will help you navigate this multifaceted software with ease.


Solid Edge ST3 for Designers is a comprehensive textbook that introduces the users to direct modeling with precise control of dimension-driven design through precision sketching and selection handles using the Solid Edge ST3 software. The textbook covers all major environments of Solid Edge ST3 in both the Synchronous and Ordered modeling with a thorough explanation of all tools, options, and their applications to create real-world products.

And some shameless self-promotion. Have you ever wondered what it takes to design and build a roller coaster? At last, there’s a book that shows you. A mix of engineering and art, roller coasters are complex three-dimensional puzzles consisting of thousands of individual parts. Designers spend countless hours creating and tweaking ride paths to push the envelope of exhilaration, all while maintaining the highest safety standards. Coasters 101: An Engineering Guide to Roller Coaster Design examines the numerous diverse aspects of roller coaster engineering, including some of the mathematical formulas and engineering concepts used.

Saturday, December 11, 2010

Coaster Model Update

Quick update on the cantilevered roller coaster model. I used my VB catscript to quickly and easily create the cross-ties for the upper and lower rails. I also modeled all of the supports and cement footers. Pictured is one of the "side/head knocker" effects where it looks like you are about to run into a post before the cantilevered car serves out of the way in the nick of time. There is also an overview of the layout. Video coming soon!






Monday, November 15, 2010

Automatically Create Cross-ties for a Roller Coaster Using VBA CATScript

Are you looking for a way to pattern an object multiple times in CATIA? How do you write catscripts in CATIA? Are you looking for a CAD model roller coaster? You've come to the write place.

If you been following this blog then you're probably aware of my work on the cantilevered roller coaster concept model. I recently created a new track to simulate the motion capability of the vehicle. I needed a quick and easy way to create all of the cross-ties which hold the two running rails together in order to create a CAD model which is as realistic as possible. At first, I was using patterns for each section of track: rectangular pattern for straight sections and circular patterns for turns and hills. This was a very time consuming process. My model contains two track that are currently around a thousand feet long. With a little bit of help from a CATIA forum, I was able to put together a CATScript which quickly and easily creates all of the cross-ties at once.


In order to get this work there are a few things that needed to be done. The rails had to be in their own separate part file. There had to be a geometrical set named "Rollercoaster." You have to select the guide curves for each rail before running the VBA code.

Here is the procedure used in the CATScript:

1. Place point1 on guidecurve1 and point2 on guidecurve2 each at equal distance from their start points.
2. Create plane normal to guidecurve1 through point1.
3. Find an intersection between normal plane and guidecurve2
4. Use near operation to select element from intersection that lie on guidecurve2 (in case if there are multiple intersections). Use point2 as reference element. Then redefine point2 to point found.
5. Place a tangent line to guidecurve1 at point1 using AddNewLineTangency method with length limits -1.5'' and 1.5'' (tangentline1)
6. Place a tangent line to guidecurve2 at point2 using AddNewLineTangency method with length limits -1.5'' and 1.5'' (tangentline2)
7. Look for points at ends of tangentline1 with AddNewPointOnCurveFromPercent method using 0% and 100% values.
8. Look for points at ends of tangentline2 with AddNewPointOnCurveFromPercent method using 0% and 100% values.
9. Connect points from 3 and 4 with lines using AddNewLinePtPt method.
10. Create new fill object using AddNewFill method and add tangent lines and lines from 5 to it using it's AddBound method.
11. Create a pad using AddNewPad method of ShapeFactory object of root part of active document.


Pictured is the track before and after the macro is ran. Here is the complete code:

Automatically Create Cross-ties for a Roller Coaster
Option Explicit

Private Const ONE_FOOT_MM = 30  ' define number of millimiteres in one foot

Private Const STEP_LENGTH = 48  ' length between cross-ties, in feet
Private Const PAD_SIDE = 3      ' length of single cross-tie side, in feet


Sub CATMain()

    ' accessing part object
    Dim RootPart As Part
    Set RootPart = CATIA.ActiveDocument.Part
   
    ' retrieving target geometrical set named "Rollercoaster"
    Dim TargetGeoSet As HybridBody
    Set TargetGeoSet = RootPart.HybridBodies.Item("Rollercoaster")
   
    ' define partbody as work object
    Dim PartBody As Body
    Set PartBody = RootPart.MainBody
   
    RootPart.InWorkObject = PartBody

    ' accessing selection object for current document
    Dim objSelection As Selection
    Set objSelection = CATIA.ActiveDocument.Selection
   
    ' retrieving reference for first curve
    Dim GuideCurve1 As AnyObject
    Set GuideCurve1 = objSelection.Item2(1).Value

    Dim refCurve1 As Reference
    If (TypeName(GuideCurve1) = "CATIAReference") Or (TypeName(GuideCurve1) = "MonoDimFeatEdge") Then
        Set refCurve1 = GuideCurve1
    Else
        Set refCurve1 = RootPart.CreateReferenceFromObject(GuideCurve1)
    End If
   
    ' retrieving reference for second curve
    Dim GuideCurve2 As Object
    Set GuideCurve2 = objSelection.Item2(2).Value

    Dim refCurve2 As Reference
    If (TypeName(GuideCurve2) = "CATIAReference") Or (TypeName(GuideCurve2) = "MonoDimFeatEdge") Then
        Set refCurve2 = GuideCurve2
    Else
        Set refCurve2 = RootPart.CreateReferenceFromObject(GuideCurve2)
    End If
   
    ' Retrieving guides' lengths
    Dim PartProd As Product
    Set PartProd = CATIA.ActiveDocument.Product
   
    Dim SPAWbench As SPAWorkbench
    Set SPAWbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
   
    Dim objMeasurable As Measurable
    Set objMeasurable = SPAWbench.GetMeasurable(refCurve1)
   
    Dim GuideLength1 As Double
    GuideLength1 = SPAWbench.GetMeasurable(refCurve1).Length
   
    Dim GuideLength2 As Double
    GuideLength2 = SPAWbench.GetMeasurable(refCurve2).Length
   
    ' Equidistance points
    Dim PointOnCurve1 As HybridShapePointOnCurve
    Dim PointOnCurve2 As HybridShapePointOnCurve
    Dim refPOC1 As Reference
    Dim refPOC2 As Reference
   
    ' Normal plane
    Dim NormalPlane As HybridShapePlaneNormal
    Dim refNPlane As Reference
   
    Dim objIntersection As HybridShapeIntersection
    Dim refIntersection As Reference
   
    Dim objNear As HybridShapeNear
    Dim refNear As Reference
   
    ' Tangent lines
    Dim TangentLine1 As HybridShapeLineTangency
    Dim TangentLine2 As HybridShapeLineTangency
    Dim refTLine1 As Reference
    Dim refTLine2 As Reference
   
    ' endpoints for tangetnt lines
    Dim TLine1EndPoint1 As HybridShapePointOnCurve
    Dim TLine1EndPoint2 As HybridShapePointOnCurve
    Dim TLine2EndPoint1 As HybridShapePointOnCurve
    Dim TLine2EndPoint2 As HybridShapePointOnCurve
    Dim refTL1EPoint1 As Reference
    Dim refTL1EPoint2 As Reference
    Dim refTL2EPoint1 As Reference
    Dim refTL2EPoint2 As Reference
   
   
    ' lines, that connect endpoints of tangent lines
    Dim BoundLine1 As HybridShapeLinePtPt
    Dim BoundLine2 As HybridShapeLinePtPt
    Dim refBLine1 As Reference
    Dim refBLine2 As Reference
   
    ' fill object
    Dim objFill As HybridShapeFill
    Dim refFill As Reference
   
    ' direction line
    Dim DirectionLine As Line
    Dim refDLine As Reference
   
    ' pad object
    Dim objPad As Pad
    Dim refPad As Pad
   
   
   
    ' construction parameters
    Dim StepLength As Double
    StepLength = STEP_LENGTH * ONE_FOOT_MM
   
    Dim PadSideLength As Double
    PadSideLength = PAD_SIDE * ONE_FOOT_MM
   
    Dim curDistance As Double
    curDistance = StepLength
   
    ' accessing factory for creating shape objects
    Dim objHSF As HybridShapeFactory
    Set objHSF = RootPart.HybridShapeFactory
   
    ' accessing factory for creating solid objects
    Dim objHF As ShapeFactory
    Set objHF = RootPart.ShapeFactory

    ' define correct direction for second curve
    Dim SecondCurveDirection As Boolean
   
    Dim NormalDirectionDistance As Double
    Dim InvertDirectionDistance As Double
   
   
    ' get distance for normal direction
    Set PointOnCurve1 = objHSF.AddNewPointOnCurveFromDistance(refCurve1, 0, True)
    Set PointOnCurve2 = objHSF.AddNewPointOnCurveFromDistance(refCurve2, 0, True)
    Set refPOC1 = RootPart.CreateReferenceFromObject(PointOnCurve1)
    Set refPOC2 = RootPart.CreateReferenceFromObject(PointOnCurve2)
   
    TargetGeoSet.AppendHybridShape PointOnCurve1
    TargetGeoSet.AppendHybridShape PointOnCurve2
   
    RootPart.Update
       
    Set objMeasurable = SPAWbench.GetMeasurable(refPOC1)
    NormalDirectionDistance = objMeasurable.GetMinimumDistance(refPOC2)
   
    objSelection.Clear
    objSelection.Add PointOnCurve2
    objSelection.Delete
   
    ' get distance for invert direction
    Set PointOnCurve2 = objHSF.AddNewPointOnCurveFromDistance(refCurve2, 0, False)
    Set refPOC2 = RootPart.CreateReferenceFromObject(PointOnCurve2)
   
    TargetGeoSet.AppendHybridShape PointOnCurve2
   
    RootPart.Update
       
    InvertDirectionDistance = objMeasurable.GetMinimumDistance(refPOC2)
   
    If (NormalDirectionDistance < InvertDirectionDistance) Then
        SecondCurveDirection = True
    Else
        SecondCurveDirection = False
    End If
   
    objSelection.Clear
    objSelection.Add PointOnCurve1
    objSelection.Add PointOnCurve2
    objSelection.Delete
       
    ' start constructing pads
    Do While (curDistance < GuideLength1)
   
        ' place point on first curve at specified distance
        Set PointOnCurve1 = objHSF.AddNewPointOnCurveFromDistance(refCurve1, curDistance, True)
        Set refPOC1 = RootPart.CreateReferenceFromObject(PointOnCurve1)
       
        ' create plane normal to first curve at initially created point
        Set NormalPlane = objHSF.AddNewPlaneNormal(refCurve1, refPOC1)
        Set refNPlane = RootPart.CreateReferenceFromObject(NormalPlane)
       
        ' define second point as intersection of normal plane and second curve
        Set objIntersection = objHSF.AddNewIntersection(refNPlane, refCurve2)
        Set refIntersection = RootPart.CreateReferenceFromObject(objIntersection)
       
        Set PointOnCurve2 = objHSF.AddNewPointOnCurveFromDistance(refCurve2, curDistance, SecondCurveDirection)
        Set refPOC2 = RootPart.CreateReferenceFromObject(PointOnCurve2)
       
        Set objNear = objHSF.AddNewNear(refIntersection, refPOC2)
        Set refNear = RootPart.CreateReferenceFromObject(objNear)
       
        Set refPOC2 = refNear
        'Set refPOC2 = RootPart.CreateReferenceFromObject(objIntersection)
       
        ' construct tangent lines
        Set TangentLine1 = objHSF.AddNewLineTangency(refCurve1, refPOC1, (-1) * PadSideLength / 2, PadSideLength / 2, True)
        Set TangentLine2 = objHSF.AddNewLineTangency(refCurve2, refPOC2, (-1) * PadSideLength / 2, PadSideLength / 2, True)
       
        TargetGeoSet.AppendHybridShape TangentLine1
        TargetGeoSet.AppendHybridShape TangentLine2
       
        ' get reference objects for tangent lines
        Set refTLine1 = RootPart.CreateReferenceFromObject(TangentLine1)
        Set refTLine2 = RootPart.CreateReferenceFromObject(TangentLine2)
       
        ' Get endpoints for tangent lines
        Set TLine1EndPoint1 = objHSF.AddNewPointOnCurveFromPercent(refTLine1, 0, True)
        Set TLine1EndPoint2 = objHSF.AddNewPointOnCurveFromPercent(refTLine1, 1, True)
       
        Set TLine2EndPoint1 = objHSF.AddNewPointOnCurveFromPercent(refTLine2, 0, SecondCurveDirection)
        Set TLine2EndPoint2 = objHSF.AddNewPointOnCurveFromPercent(refTLine2, 1, SecondCurveDirection)
       
        TargetGeoSet.AppendHybridShape TLine1EndPoint1
        TargetGeoSet.AppendHybridShape TLine1EndPoint2
        TargetGeoSet.AppendHybridShape TLine2EndPoint1
        TargetGeoSet.AppendHybridShape TLine2EndPoint2
       
        ' get reference objects for endpoints
        Set refTL1EPoint1 = RootPart.CreateReferenceFromObject(TLine1EndPoint1)
        Set refTL1EPoint2 = RootPart.CreateReferenceFromObject(TLine1EndPoint2)
        Set refTL2EPoint1 = RootPart.CreateReferenceFromObject(TLine2EndPoint1)
        Set refTL2EPoint2 = RootPart.CreateReferenceFromObject(TLine2EndPoint2)
       
        ' construct bound lines
        Set BoundLine1 = objHSF.AddNewLinePtPt(refTL1EPoint1, refTL2EPoint1)
        Set BoundLine2 = objHSF.AddNewLinePtPt(refTL1EPoint2, refTL2EPoint2)
       
        TargetGeoSet.AppendHybridShape BoundLine1
        TargetGeoSet.AppendHybridShape BoundLine2
       
        Set refBLine1 = RootPart.CreateReferenceFromObject(BoundLine1)
        Set refBLine2 = RootPart.CreateReferenceFromObject(BoundLine2)
       
        ' create fill with contour
        Set objFill = objHSF.AddNewFill()
       
        objFill.AddBound refTLine1
        objFill.AddBound refBLine1
        objFill.AddBound refTLine2
        objFill.AddBound refBLine2
       
        TargetGeoSet.AppendHybridShape objFill
       
        Set refFill = RootPart.CreateReferenceFromObject(objFill)
       
        ' create direction
        Set DirectionLine = objHSF.AddNewLineNormal(refFill, refTL1EPoint1, False, -5, 5)
        Set refDLine = RootPart.CreateReferenceFromObject(DirectionLine)
       
        TargetGeoSet.AppendHybridShape DirectionLine
       
        ' create pad
        Set objPad = objHF.AddNewPadFromRef(refFill, PadSideLength / 2)
       
        ' define pad limits
        objPad.FirstLimit.Dimension.Value = PadSideLength / 2
        objPad.SecondLimit.Dimension.Value = PadSideLength / 2
       
        ' set direction
        objPad.SetDirection refDLine
       
        ' move to construction of the next pad
        curDistance = curDistance + StepLength
    Loop
   
    ' Update part to see added objects
    RootPart.Update


End Sub

Wednesday, July 14, 2010

How do you write a CATIA CATScript Macro?


A question I often get asked is "how do you create vba macros in Catia?" One solution is to write a script. No, not a script for a movie, a CATScript file! To create a CATScript macro for CATIA open Notepad and write your code, then save the file with whatever name you want and type extension .CATScript instead of .txt. Here is a simple CATScript you can use as an example. This CATScript will tell you which version of Catia you are currently using, including the service pack number. Copy and paste the code into Notepad then save as CatiaVersion.CATScript.


 

Sub CATMain()

Set SystemConfiguration1 = CATIA.SystemConfiguration

Msgbox "CATIA V" & SystemConfiguration1.Version & " R " & SystemConfiguration1.Release & " sp " & SystemConfiguration1.ServicePack
End Sub


Now you are on your way to writing your own CATScript macros and automating simple and repetitive processes!

Learn how to write CATScript macros Lesson 1.

Learn how to write CATIA CATSCRIPT MACROS