Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

creating of dimension in drawing document

Status
Not open for further replies.

AbhishekParvat

Mechanical
May 30, 2023
2
0
0
IN
Hello, i am facing issue while creating dimension in drawing document. Actually it generating all the dimension at one point. I am sharing my code
Private Sub length_dim1_Click()
Dim CATIA As Object
Dim drawingdocumentdim1 As Object
Dim drawingsheetsdim As Object
Dim drawingsheetdim As Object
Dim drawingviewsdim As Object
Dim drawingviewdim As Object
Dim strLine As String
Dim line1 As Line2D
Dim linesel1 As Object
Dim inputline()
Dim statussel3
Dim selpoint(1)

Dim selpoints(3)
selpoints(3) = Array(150, 10, 120, 100)

selpoint(0) = 0
selpoint(1) = 0

' Set CATIA application
Set CATIA = GetObject(, "CATIA.Application")

' Get the active drawing document
Set drawingdocumentdim1 = CATIA.ActiveDocument
Set drawingsheetsdim = drawingdocumentdim1.Sheets
Set drawingsheetdim = drawingsheetsdim.ActiveSheet

' Get the active drawing view
Set drawingviewsdim = drawingsheetdim.Views
Set drawingviewdim = drawingsheetdim.Views.ActiveView

' Initialize the object selection for lines
Set linesel1 = drawingdocumentdim1.selection

' Prompt user for auto dimensions
answermsg1 = MsgBox("Do you want auto dimensions", vbYesNo + vbSystemModal, "")

If answermsg1 = vbYes Then
' Search for all lines
strLine = "Drafting.Line,all"
linesel1.Search strLine
Else
' Prompt user to select line
MsgBox "Select Curve"
inputline(0) = "AnyObject"
statussel3 = linesel1.SelectElement3(inputline, "select Curve", False, CATMultiSelectionMode.CATMultiSelTriggWhenUserValidatesSelection, False)
If statussel3 = "Cancel" Then
Exit Sub
End If
End If

' Get the count of selected lines
Dim icount
icount = linesel1.Count

' Loop through selected lines and add length dimensions
Dim i
[highlight #FCE94F] For i = 1 To icount
' Get the selected line
Set line1 = linesel1.Item(i).Value
ReDim inputline(0 To i)
inputline(i) = Array(line1)
' Add length dimension to the drawing view
drawingviewdim.Dimensions.Add CatDimType.catDimLength, inputline(i), selpoints(3), CatDimLineRep.catDimAuto
Next i
[/highlight]
pic_dgrwao.png

End Sub
 
Replies continue below

Recommended for you

since you are resizing the inputline inside your loop, you need to preserve your previous values :)
or, alternatively move the redim statement to outside the loop
Code:
ReDim inputline(0 To icount)
For i = 1 To icount
' Get the selected line
    Set line1 = linesel1.item(i).Value
    inputline(i) = Array(line1)
' Add length dimension to the drawing view
    drawingviewdim.Dimensions.Add CatDimType.catDimLength, inputline(i), selpoints(3), CatDimLineRep.catDimAuto
Next i

'alternatively:
For i = 1 To icount
' Get the selected line
Set line1 = linesel1.Item(i).Value
ReDim preserve inputline(0 To i)
inputline(i) = Array(line1)
' Add length dimension to the drawing view
drawingviewdim.Dimensions.Add CatDimType.catDimLength, inputline(i), selpoints(3), CatDimLineRep.catDimAuto
Next i

regards,
LWolf
 
Hello all, can any one share the code for generating the dimension from center or hole to edge in drafting through CATIA VBA. Because i am not getting how to do this task and we can record macros also in drafting.
 
Status
Not open for further replies.
Back
Top