Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

인벤터 - idw 자동화된 중심선 logic 작성 중 질문

ickis1492
Enthusiast

인벤터 - idw 자동화된 중심선 logic 작성 중 질문

ickis1492
Enthusiast
Enthusiast

매번 누르는게 귀찮아서 view 작성 할 때마다 자동으로 센터라인을 작성하고 싶습니다.

그래서 chat gpt를 한 시간 괴롭힌 결과 이런 코드를 작성해 주었습니다. 하지만 역시 작동 하지 않는군요.

뷰를 찾아서 순차적으로 적용 메시지 창이 뜨고 버튼을 누르면 실행할 수 있도록 했는데. 
이것이 동작하지 않는 것 같습니다.  상세 전체 코드는 아래에 첨부하였습니다.

' 설정에 따라 자동 중심선 및 중심 마크 추가 명령 실행
                ThisApplication.CommandManager.ControlDefinitions.Item("DrawingAutoCenterlinesCmd").Execute()

 

  • ThisApplication: 현재 Autodesk Inventor 응용 프로그램 인스턴스를 참조합니다.

  • CommandManager: Inventor에서 사용자 명령을 관리하는 객체입니다. CommandManager를 통해 사용자 인터페이스에 있는 명령어들을 코드로 실행할 수 있습니다.

  • ControlDefinitions: CommandManager에서 사용할 수 있는 모든 명령의 정의를 보유한 컬렉션입니다. 이 컬렉션에서 특정 명령을 Item으로 호출하여 해당 명령에 접근할 수 있습니다.

  • "DrawingAutoCenterlinesCmd": 이 문자열은 자동 중심선을 추가하는 명령의 고유 ID입니다. 이 명령어는 특정 버전의 Autodesk Inventor에서 사용 가능한 명령일 수 있지만, 모든 버전에서 항상 사용할 수 있는 것은 아닙니다. 일반적으로 명령 ID는 Autodesk Inventor 버전에 따라 다르며, 특정 기능이 제거되거나 이름이 변경될 수 있습니다.

  • Execute(): Execute() 메서드는 선택한 명령을 실행합니다. 여기서는 "DrawingAutoCenterlinesCmd"에 대한 Execute() 호출을 통해 뷰에 자동으로 중심선을 추가하려는 것입니다.

    이라고 chat gpt는 말하는데.. 뭔가 오묘한 거짓이 섞여 있는 것 같습니다. automated centerlines 명령어를 실행할 수 있는 방법에 대해 조언 부탁 드립니다. 

 

 

ickis1492_0-1730071469657.png

 

 

Sub Main()
    ' 활성 문서가 도면 문서인지 확인
    Dim oDoc As DrawingDocument
    oDoc = ThisApplication.ActiveDocument
    If oDoc.DocumentType <> kDrawingDocumentObject Then
        MsgBox("IDW 파일에서 이 코드를 실행하세요.")
        Exit Sub
    End If

    ' 문서의 기본 자동 중심선 설정 가져오기
    Dim settings As AutomatedCenterlineSettings
    settings = oDoc.DrawingSettings.AutomatedCenterlineSettings

    ' 자동 중심선 설정 구성
    settings.ApplyToHoles = True ' 구멍에 중심선 적용
    settings.ApplyToCylinders = True ' 원통형 피처에 중심선 적용
    settings.ApplyToRevolutions = True ' 회전체 피처에 중심선 적용
    settings.ApplyToCircularPatterns = True ' 원형 패턴에 중심선 적용
    settings.ProjectionParallelAxis = True ' 평행축으로 투영 적용
    settings.ProjectionNormalAxis = False ' 수직축으로 투영 적용하지 않음

    ' 각 시트의 각 뷰를 차례로 진행
    Dim oSheet As Sheet
    Dim oView As DrawingView
    Dim oCenterline As Centerline
    Dim oCenterEntities As ObjectCollection
    oCenterEntities = ThisApplication.TransientObjects.CreateObjectCollection()

    For Each oSheet In oDoc.Sheets
        For Each oView In oSheet.DrawingViews
            ' 사용자에게 뷰 처리 여부 확인 메시지 표시
            Dim response As Integer
            response = MsgBox("이 뷰에 중심선과 중심 마크를 추가하시겠습니까?", vbYesNo + vbQuestion, "뷰 처리")

            If response = vbYes Then
                ' 각 뷰에 자동 중심선 설정 적용
                oView.SetAutomatedCenterlineSettings(settings)

                ' 설정에 따라 자동 중심선 및 중심 마크 추가 명령 실행
                ThisApplication.CommandManager.ControlDefinitions.Item("DrawingAutoCenterlinesCmd").Execute()
                ThisApplication.CommandManager.ControlDefinitions.Item("DrawingAutoCenterMarksCmd").Execute()

                ' 특정 중심선 추가: CenterEntities 모음 정의
                ' 예를 들어, 첫 번째와 두 번째 원형 선을 중심선 엔티티로 지정
                oCenterEntities.Add(oView.DrawingCurves(1).GeometryIntent)
                oCenterEntities.Add(oView.DrawingCurves(2).GeometryIntent)

                ' 중심선 추가 (기본 센터 마크 스타일과 레이어 사용, 닫힌 중심선이 아님)
                oCenterline = oView.Centerlines.Add(oCenterEntities, , , False)

                MsgBox("중심선과 중심 마크가 추가되었습니다.")
            End If
        Next
    Next

    MsgBox("모든 뷰 처리가 완료되었습니다.")
End Sub


 

0 Likes
Reply
152 Views
4 Replies
Replies (4)

hyosun_jung
Community Manager
Community Manager

고수님들의 답변을 기다립니다~ 😀


게시글과 답변이 유용하다면 "좋아요"를 눌러주세요~

질문이 해결된 답변에 "솔루션 수락"을 눌러주세요~


Autodesk Community - Korean Community Manager, Hyosun Jung
0 Likes

손광호
Collaborator
Collaborator

하기 링크의 내용을 참고하시면 어떨까요?

 

https://spiderinnet2.typepad.com/blog/2012/07/inventor-net-find-all-the-control-definitions-1.html

 

자동화된 중심선... - DrawingAutomatedCenterlinesCtxCmd 명령이 있고 

 

뷰 배치 시 자동 중심선 기능을 추가하실려면

 

뷰배치 구문에 자동 중심선 규칙을 실행하는 구문을 한줄 추가하시는 부분도 방법일듯 합니다.

 

iLogicVb.RunRule("Automatic_CenterLine")

 

줌인테크 Techanical Support Engineer

hyosun_jung
Community Manager
Community Manager

@손광호 오! 답변 감사합니다~ 😀 


게시글과 답변이 유용하다면 "좋아요"를 눌러주세요~

질문이 해결된 답변에 "솔루션 수락"을 눌러주세요~


Autodesk Community - Korean Community Manager, Hyosun Jung
0 Likes

hyosun_jung
Community Manager
Community Manager

@ickis1492 답변을 참고하시고 적용 후기도 들려주세요~ 감사합니다. 😊


게시글과 답변이 유용하다면 "좋아요"를 눌러주세요~

질문이 해결된 답변에 "솔루션 수락"을 눌러주세요~


Autodesk Community - Korean Community Manager, Hyosun Jung
0 Likes