0

.net APIに関する質問です。

ブロック参照のクリップ範囲を取得する際に、
GrxCAD.DatabaseServices.Filters.SpatialFilterDefinition.GetPoints()
(※1)で取得していますが、クリップの設定により下記の通り挙動が変わります。

※1 (外部参照クリップ境界の座標値を取得する方法)参照

①プログラムでクリップを設定(※2)した場合:
ブロック座標系でのクリップ範囲の座標値を返す。
※2下記ソースコード参照

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry

<CommandMethod("ClippingExternalReference")> _
Public Sub ClippingExternalReference()
    ' Get the current database and start a transaction
    Dim acCurDb As Autodesk.AutoCAD.DatabaseServices.Database
    acCurDb = Application.DocumentManager.MdiActiveDocument.Database

    Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
        ' Create a reference to a DWG file
        Dim PathName As String = "C:\AutoCAD\Sample\Sheet Sets\Architectural\Res\Exterior Elevations.dwg"
        Dim acXrefId As ObjectId = acCurDb.AttachXref(PathName, "Exterior Elevations")

        ' If a valid reference is created then continue
        If Not acXrefId.IsNull Then
            ' Attach the DWG reference to the current space
            Dim insPt As New Point3d(1, 1, 0)
            Using acBlkRef As New BlockReference(insPt, acXrefId)

                Dim acBlkTblRec As BlockTableRecord
                acBlkTblRec = acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite)

                acBlkTblRec.AppendEntity(acBlkRef)
                acTrans.AddNewlyCreatedDBObject(acBlkRef, True)

                MsgBox("The external reference is attached.")

                Dim mat As Matrix3d = acBlkRef.BlockTransform
                mat.Inverse()

                Dim ptCol As New Point2dCollection

                ' Define the first corner of the clipping boundary
                Dim pt3d As New Point3d(-330, 400, 0)
                pt3d.TransformBy(mat)
                ptCol.Add(New Point2d(pt3d.X, pt3d.Y))

                ' Define the second corner of the clipping boundary
                pt3d = New Point3d(1320, 1120, 0)
                pt3d.TransformBy(mat)
                ptCol.Add(New Point2d(pt3d.X, pt3d.Y))

                ' Define the normal and elevation for the clipping boundary 
                Dim normal As Vector3d
                Dim elev As Double = 0

                If acCurDb.TileMode = True Then
                    normal = acCurDb.Ucsxdir.CrossProduct(acCurDb.Ucsydir)
                    elev = acCurDb.Elevation
                Else
                    normal = acCurDb.Pucsxdir.CrossProduct(acCurDb.Pucsydir)
                    elev = acCurDb.Pelevation
                End If

                ' Set the clipping boundary and enable it
                Using filter As New Filters.SpatialFilter
                    Dim filterDef As New Filters.SpatialFilterDefinition(ptCol, normal, elev, 0, 0, True)
                    filter.Definition = filterDef

                    ' Define the name of the extension dictionary and entry name
                    Dim dictName As String = "ACAD_FILTER"
                    Dim spName As String = "SPATIAL"

                    ' Check to see if the Extension Dictionary exists, if not create it
                    If acBlkRef.ExtensionDictionary.IsNull Then
                        acBlkRef.UpgradeOpen()
                        acBlkRef.CreateExtensionDictionary()
                        acBlkRef.DowngradeOpen()
                    End If

                    ' Open the Extension Dictionary for write
                    Dim extDict As DBDictionary = acTrans.GetObject(acBlkRef.ExtensionDictionary, OpenMode.ForWrite)

                    ' Check to see if the dictionary for clipped boundaries exists, 
                    ' and add the spatial filter to the dictionary
                    If extDict.Contains(dictName) Then
                        Dim filterDict As DBDictionary = acTrans.GetObject(extDict.GetAt(dictName), OpenMode.ForWrite)

                        If (filterDict.Contains(spName)) Then filterDict.Remove(spName)

                        filterDict.SetAt(spName, filter)
                    Else
                        Using filterDict As New DBDictionary
                            extDict.SetAt(dictName, filterDict)

                            acTrans.AddNewlyCreatedDBObject(filterDict, True)
                            filterDict.SetAt(spName, filter)
                        End Using
                    End If

                    ' Append the spatial filter to the drawing
                    acTrans.AddNewlyCreatedDBObject(filter, True)
                End Using
            End Using

            MsgBox("The external reference is clipped.")
        End If

        ' Save the new objects to the database
        acTrans.Commit()

        ' Dispose of the transaction
    End Using
End Sub

(参照元:https://knowledge.autodesk.com/ja/search-result/caas/CloudHelp/cloudhelp/2016/JPN/AutoCAD-NET/files/GUID-72029044-0840-4187-9A58-F2A4518E3A23-htm.html

②IJCADのXCLIPでクリップを設定した場合:
全体座標系でのクリップ範囲の座標値を返す。

これはプログラミングに問題があるのでしょうか?

開発環境はVisual Staudio VB.net、IJCAD2016です。

お手数ですが、情報提供いただけますと助かります。

1 件の回答 1

0

Autodeskのサンプルコードを元にして作成したコマンドで外部参照を作成し、外部参照からSpatialFilterDefinition.GetPointsメソッドでクリップ範囲の座標点を取得してコマンドラインに出力してみましたが、AutoCADもIJCADもブロック座標系での座標値が返されました。

Clip point = (-331,399)
Clip point = (1319,1119)

恐らくプログラミングに問題があると思いますので、クリップ範囲の座標系を取得しているコードに、問題が無いかどうか見直してみてはいかがでしょうか。

AutoCAD
画像の説明をここに入力

IJCAD
画像の説明をここに入力

追記:
SpatialFilter.OriginalInverseBlockTransformプロパティで、Filterが最後に設定されたときに関連付けられたブロック変換を取得できますので、これで全体座標系かブロック座標系か判断できると思います。

3
  • ご回答ありがとうございます。また、返信が遅れて申し訳ありません。ちなみに作成されましたブロック参照に対してIJCADのXCLIPコマンドで表示領域を再設定し、再度SpatialFilterDefinition.GetPointsメソッドでクリップ範囲の座標点を取得した結果はいかがでしょうか。ブロック座標系ではなく全体座標系の座標値を返していると思われます。
    – YAMADA
    2019年9月20日 7:38
  • AutoCADでもXCLIPコマンドを使用してクリップ範囲の新しい境界を設定した場合は全体座標系に変更されていますので、IJCADでもXCLIPコマンドを使用した場合で全体座標系に変更されてしまうのは正しい動きだと思われます。
    – user30469
    2019年9月24日 2:33
  • ご回答ありがとうございます。クリップ範囲取得の挙動が変わることは仕様だということを理解しました。改めて質問なのですが、GetPointsメソッドでクリップの範囲を取得する際にXCLIPで設定されたのかどうか(つまり全体座標系が返ってくるのか、ブロック座標系が返ってくるのか)を判断することは可能でしょうか?
    – YAMADA
    2019年9月25日 1:16

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。