Chuyển đến nội dung
Diễn đàn CADViet

MinhTri782015

Thành viên
  • Số lượng nội dung

    4
  • Đã tham gia

  • Lần ghé thăm cuối

Bài đăng được đăng bởi MinhTri782015


  1. nhờ các bạn chỉ giúp, lỗi đoạn code, tại sao ko nhận hết dim, text, leader trong sset2 mà lúc được lúc ko, và có lúc chỉ nhận riêng từng đối tượng.

     

    Public Sub S1() 


    'chọn đối tượng block để lấy hệ số scalefactor
    Dim Object As AcadBlockReference
    Dim sset2 As AcadSelectionSet
    Dim a As Double
    Dim Ent As AcadEntity
    Dim P1 As AcadDimension
    Dim P4 As AcadLeader

    On Error Resume Next
    ThisDrawing.SelectionSets("ml2").Delete
    Set sset2 = ThisDrawing.SelectionSets.Add("ml2")
    sset2.SelectOnScreen
    For Each Object In sset2
    a = Object.XScaleFactor
    Next

     

    'chọn dim, text, leader để lấy theo giá trị của hệ số dimsclale

     

    Dim STRING1 As String
    Dim objdimstyle As AcadDimStyle
    'choose the dimstyle

    'CHOOSE the Mtext to changing height text
    Dim GpCode(5) As Integer
    Dim dataValue(5) As Variant

    GpCode(0) = -4: dataValue(0) = "<or"
    GpCode(1) = 0: dataValue(1) = "MTEXT"
    GpCode(2) = 0: dataValue(2) = "TEXT"
    GpCode(3) = 0: dataValue(3) = "DIMENSION"
    GpCode(4) = 0: dataValue(4) = "LEADER"

    GpCode(5) = -4: dataValue(5) = "or>"

    Dim sset21 As AcadSelectionSet
    On Error Resume Next
    ThisDrawing.SelectionSets("ml21").Delete
    Set sset21 = ThisDrawing.SelectionSets.Add("ml21")
    sset21.SelectOnScreen GpCode, dataValue
    On Error Resume Next
    MsgBox "So doi tuong duoc chon: " & SSetObj.Count

    For Each Ent In sset21
     Ent.Height = 2 * a

    Next
    STRING1 = "A3S " & a

    For Each objdimstyle In ThisDrawing.DimStyles
    If STRING1 = objdimstyle.Name Then

    For Each P1 In sset21
    P1.StyleName = STRING1

    Next

    For Each P4 In sset21
    P4.StyleName = STRING1
    Next
    Exit Sub
    End If
    Next
    Set objdimstyle = ThisDrawing.DimStyles.Add(STRING1)
    ThisDrawing.SetVariable "dimscale", a
    objdimstyle.CopyFrom ThisDrawing

    For Each P1 In sset21
    P1.StyleName = STRING1
    Next

    For Each P4 In sset21
    P4.StyleName = STRING1
    Next

    End Sub
     


  2. xin cac cao nhân chỉ giáo, sửa giúp cái code, tại sao nó chỉ chọn một là dim hai là text. mà ko thay đổi tất cả trong cùng một selectionset

     

    Public Sub S1() 'chosing the dimstyle follow the frame block

    'choose the frame block to use the scale factor

    Dim Object As AcadBlockReference

    Dim sset2 As AcadSelectionSet

    Dim a As Double

    Dim Ent As AcadEntity

    Dim P1 As AcadDimension

    Dim P4 As AcadLeader

     

    On Error Resume Next

    ThisDrawing.SelectionSets("ml2").Delete

    Set sset2 = ThisDrawing.SelectionSets.Add("ml2")

    sset2.SelectOnScreen

    For Each Object In sset2

    a = Object.XScaleFactor

    Next

     

    Dim string1 As String

    Dim objdimstyle As AcadDimStyle

    'choose the dimstyle

     

    'CHOOSE the Mtext to changing height text

    Dim GpCode(5) As Integer

    Dim dataValue(5) As Variant

     

    GpCode(0) = -4: dataValue(0) = "<or"

    GpCode(1) = 0: dataValue(1) = "MTEXT"

    GpCode(2) = 0: dataValue(2) = "TEXT"

    GpCode(3) = 0: dataValue(3) = "DIMENSION"

    GpCode(4) = 0: dataValue(4) = "LEADER"

     

    GpCode(5) = -4: dataValue(5) = "or>"

     

    Dim sset21 As AcadSelectionSet

    On Error Resume Next

    ThisDrawing.SelectionSets("ml21").Delete

    Set sset21 = ThisDrawing.SelectionSets.Add("ml21")

    sset21.SelectOnScreen GpCode, dataValue

     

    On Error Resume Next

     

    For Each Ent In sset21

     Ent.Height = 2 * a

     

    Next

    string1 = "A3S " & a

     

    For Each objdimstyle In ThisDrawing.DimStyles

    If string1 = objdimstyle.Name Then

     

     

    'ThisDrawing.ActiveDimStyle = ThisDrawing.DimStyles(string1)

     

    For Each P1 In sset21

    P1.StyleName = string1

     

    Next

     

    For Each P4 In sset21

    P4.StyleName = string1

    Next

    Exit Sub

    End If

    Next

    Set objdimstyle = ThisDrawing.DimStyles.Add(string1)

    ThisDrawing.SetVariable "dimscale", a

    objdimstyle.CopyFrom ThisDrawing

    'ThisDrawing.ActiveDimStyle = ThisDrawing.DimStyles(string1)

     

    For Each P1 In sset21

    P1.StyleName = string1

    Next

     

    For Each P4 In sset21

    P4.StyleName = string1

    Next

     

    End Sub

×