romaleee
Mechanical
- May 13, 2016
- 37
Hello,
here I have some code that I work on and I've hit a wall.
What it does. The idea is that the "break view" in drawing always has same size no mater if the referenced part changes its length. So I decided to automatically remove a existing break and create a new one according to new "3d part length". I want to put the code in VBScript (Macro with Arguments) and call it with reaction. I've written the code and it works in VBA. However when i copy the code in VBScript I get several errors that I do not know how to solve. Please help me someone .
Code:
How it looks like in VBScript:
Error I get:
If I made some irrational mistakes in my coding I apologize in front. I'm not a professional programer .
Thank you in advance.
Roman
here I have some code that I work on and I've hit a wall.
What it does. The idea is that the "break view" in drawing always has same size no mater if the referenced part changes its length. So I decided to automatically remove a existing break and create a new one according to new "3d part length". I want to put the code in VBScript (Macro with Arguments) and call it with reaction. I've written the code and it works in VBA. However when i copy the code in VBScript I get several errors that I do not know how to solve. Please help me someone .
Code:
Code:
Sub CATMain()
' first part of code used to define a View. It will not be needed later when I plan to inport rest of the code in VBScript - Macro With arguments
Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument
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("Bottom view")
Dim parameters1 As Parameters
Set parameters1 = drawingDocument1.Parameters
Dim length1 As Length
Set length1 = parameters1.Item("Drawing\Duljina_letvice")
Dim drawingViewGenerativeBehavior1 As DrawingViewGenerativeBehavior
Set drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior
Set drawingViewGenerativeBehavior1Variant = drawingViewGenerativeBehavior1
'define array for positions of horizontal dim lines
Dim visine() As String
ReDim visine(1, 0)
'call sub for extracting the positions
Call GetPositions(drawingView1, visine())
'unbreak view
drawingViewGenerativeBehavior1Variant.UnBreak
Dim koord As Double
'set position of upper break line
koord = length1.Value - 60
'define new broken view
Dim arrayOfVariantOfDouble1(7)
arrayOfVariantOfDouble1(0) = 0#
arrayOfVariantOfDouble1(1) = 50#
arrayOfVariantOfDouble1(2) = 9#
arrayOfVariantOfDouble1(3) = 50#
arrayOfVariantOfDouble1(4) = 0#
arrayOfVariantOfDouble1(5) = koord
arrayOfVariantOfDouble1(6) = 0#
arrayOfVariantOfDouble1(7) = koord
drawingViewGenerativeBehavior1Variant.DefineBrokenView arrayOfVariantOfDouble1, 0#, 1#
'define new position of view
drawingView1.y = length1.Value / 2 + 125#
'call sub for updating the dim value position
Call UpdatePositions(drawingView1, visine())
End Sub
Sub GetPositions(oView As DrawingView, oArray() As String)
Dim drawingDimension1 As DrawingDimension
Dim oLine As Object
For Each drawingDimension1 In oView.Dimensions
Set oLine = drawingDimension1.GetDimLine
'define array that collects coordinates from dimline
Dim info() As Variant
ReDim info(5)
'collect coordinates
Call oLine.GetGeomInfo(info())
'Extract coordinate for vertical position
If Round(info(1), 5) = Round(info(3), 5) Then
oArray(0, UBound(oArray, 2)) = drawingDimension1.Name
oArray(1, UBound(oArray, 2)) = info(1)
ReDim Preserve oArray(1, UBound(oArray, 2) + 1)
End If
Next
ReDim Preserve oArray(1, UBound(oArray, 2) - 1)
End Sub
'sets horizontal dimvalues to proper position
Sub UpdatePositions(oView As DrawingView, oArray() As String)
Dim drawingDimension1 As DrawingDimension
Dim oValue As DrawingDimValue
Dim i As Integer
For i = 0 To UBound(oArray(), 2)
Set drawingDimension1 = oView.Dimensions.Item(oArray(0, i))
'set vertical position of value
drawingDimension1.MoveValue 0, CDbl(oArray(1, i)), 0, 1
'restore horizontal position
drawingDimension1.RestoreValuePosition
Next
End Sub
How it looks like in VBScript:
Error I get:
If I made some irrational mistakes in my coding I apologize in front. I'm not a professional programer .
Thank you in advance.
Roman