Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to move Selected elements to a distance of XX mm from its original location

Status
Not open for further replies.

Maddy02

Mechanical
Feb 14, 2013
114
IN
Hi Guys,

I would like to know is there any way to move some selected elements with reference to coordinates / some distance.

' A collection of line, text, and circle.
Set oSel = ActiveDoc.Selection
oSel.Add oText
oSel.Add oLine
oSel.Add oCircle

These selected entities has to be moved to a certain distance of XX mm from theirs original location (2D - in drawing)

Regards,
Maddy

Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 
Replies continue below

Recommended for you

@Maddy02
No. I couldn't find anything in the API for being able to move all three items at once within a selection. There are other ways to move them, but not altogether within a selection.

This is a workaround option, but you could use CATIA.StartCommand "Translate" and then call an external vbscript that uses sendkeys to complete the translate command. The code for the vba module would look like this:

Code:
Sub CATMain()

Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument

Dim oSel As Selection
Set oSel = drawingDocument1.Selection

Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets

Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.Item("Sheet.1")

Dim drawingViews1 As DrawingViews
Set drawingViews1 = drawingSheet1.Views

Dim drawingView1 As DrawingView
Set drawingView1 = drawingViews1.Item("Front view")

Dim drawingTexts1 As DrawingTexts
Set drawingTexts1 = drawingView1.Texts

Dim oText As DrawingText
Set oText = drawingTexts1.GetItem("Text.2")

Dim geometricElements1 As GeometricElements
Set geometricElements1 = drawingView1.GeometricElements

Dim oLine As Line2D
Set oLine = geometricElements1.Item("Line.1")

Dim oCircle As Circle2D
Set oCircle = geometricElements1.Item("Circle.1")

oSel.Clear
oSel.Add oText
oSel.Add oLine
oSel.Add oCircle

CATIA.StartCommand "Translate"

Dim cmd As String
cmd = "wscript C:\Users\Drew\Desktop\move.vbs"

Call Shell(cmd)

End Sub

The vba calls a vbs file called "move.vbs". The code within "move.vbs" would look like this (it simulates the keystrokes required to finish the translate command):

Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep 600
WshShell.AppActivate "CATIA V5"
WScript.Sleep 600
WshShell.SendKeys "{TAB}", TRUE
WScript.Sleep 600
WshShell.SendKeys "0", TRUE
WScript.Sleep 600
WshShell.SendKeys "{TAB}", TRUE
WScript.Sleep 600
WshShell.SendKeys "0", TRUE
WScript.Sleep 600
WshShell.SendKeys "{ENTER}", TRUE
WScript.Sleep 600
WshShell.SendKeys "5", TRUE
WScript.Sleep 600
WshShell.SendKeys "{TAB}", TRUE
WScript.Sleep 600
WshShell.SendKeys "0", TRUE
WScript.Sleep 600
WshShell.SendKeys "{ENTER}", TRUE

Regards,
Drew Mumaw
 
Hi,

@ Drew Mumaw

Thanks alot for the reply.
Will go through the code and see will work out or not.

but is there any possibility to un-check the duplicate option in Translate Definition Window.
As this will create a copy of the elements which is not required.

Regards,
Maddy

Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 

Also could you elaborate on finding the active window in CATIA and then switch between them.
May be this might help in achieving above un-check option.
(In above case two windows will come up i.e. Tools Palette and Translation Definition.)

Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 
@Maddy02
I'll look into it, but first let me ask you, based upon your scenario, would it be possible to apply a fix together constraint to the line, circle, and text? Then you could create a vertical and horizontal driving dimension to a point on the line and control the dimensions with a much simpler (and more reliable) script. Doing it this way would get rid of the need for having to select them in the first place. If you are able to do this then you might have to right-click on the text and select Positional Link > Create and then select the line, so that the text moves in relation to the line (and circle).

Regards,
Drew Mumaw
 
@Maddy02
Maddy02 said:
is there any possibility to un-check the duplicate option in Translate Definition Window.
Yes, it will just require some modifications to the move.vbs file. Also, if you use the translate command once in your CATIA session and uncheck the duplicate option, then it will remain unchecked the next time you use it as well. So if you were to use the translate command and uncheck that option and then run my script, it should work better.

Also, you'll have to modify my original vba code since I was assuming those elements were in "Sheet.1" and "Front view" and named "Line.1", etc. You'll need to change these items to fit your specific use case.

Regards,
Drew Mumaw
 
this will move all line and circle in a selection (from the same 2DView)

Code:
Sub CATMain()
Dim partDocument1 As DrawingDocument
Set partDocument1 = CATIA.ActiveDocument

Dim oSelObjType As String
Dim oSelObject As AnyObject

'***********************************************************************************************************
'
'define the translation here
'
'***********************************************************************************************************

Dim deltaX As Double
Dim deltaY As Double


deltaX = 0
deltaY = 1000

'***********************************************************************************************************
'
' going through the selection
'
'***********************************************************************************************************

For i = 1 To partDocument1.Selection.Count
    
    Set oSelObj = partDocument1.Selection.Item(i).Value
    oSelObjType = TypeName(oSelObj)
    
' check the type of the selected item and action accordingly
' this will move only circles and lines in selection

    Select Case oSelObjType
        
        Case "Circle2D"
        
            moveCircle oSelObj, deltaX, deltaY
        
        Case "Line2D"
        
            If TypeName(oSelObj.Parent) <> "Axis2D" Then  ' Axis vector are line2D type, we need to exclude this
                moveLine oSelObj, deltaX, deltaY
            End If
        
    End Select

Next i

End Sub

Private Sub moveCircle(oCircle, dX As Double, dY As Double)

    Dim oCtr(1)
    oCircle.GetCenter oCtr
    
    Dim myCenter, oStartPoint, oEndPoint As Point2D
    Set myCenter = oCircle.CenterPoint
    Set oStartPoint = oCircle.StartPoint
    Set oEndPoint = oCircle.EndPoint
    
    movePoint myCenter, dX, dY
    movePoint oStartPoint, dX, dY
    movePoint oEndPoint, dX, dY
    
    
    oCircle.SetData oCtr(0) + dX, oCtr(1) + dY, oCircle.Radius

End Sub

Private Sub movePoint(oPt, dX As Double, dY As Double)

Dim oCoord(1)
oPt.GetCoordinates oCoord

oPt.SetData oCoord(0) + dX, oCoord(1) + dY


End Sub

Private Sub moveLine(oLine, dX As Double, dY As Double)

Dim oStartPt, oEndPt As Point2D
Dim myDir(1)
Dim oPtCoord(1)

oLine.GetDirection myDir

Set oStartPt = oLine.StartPoint
Set oEndPt = oLine.EndPoint

oStartPt.GetCoordinates oPtCoord

movePoint oStartPt, dX, dY
movePoint oEndPt, dX, dY

oLine.SetData oPtCoord(0) + dX, oPtCoord(1) + dY, myDir(0), myDir(1)

End Sub

Eric N.
indocti discant et ament meminisse periti
 
Hi,
@ferdo
I suppose your elements are not Generated Items. Then, why don't you get only the values, store them in a collection, recreate where you want by code and delete from the old location?

Ya they are not generated items. Indeed i tried to re-create exactly as you mentioned but
I was unable to recreate one type of element (Circle with 1/2 portion colored) out of the selected
geometric elements which contains coloring.
I suppose this can be done interactively by hatching and
in regard to hatching i haven't found any API while going through the documentation.

Moreover it'll take lot of time to recreate entities in this case
( manually drawn view consisting a two different logos with >1000 lines itself, add to that this logo is present at 3 places )

@itsmyjob
Thanks a lot man you saved my day. your function works exactly as expected.
I can move the above described circle case (1/2 section colored) as desired.

Earlier i forgot to mention a case of an arc. Will try to work out.

Regards,
Maddy



Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top