Reply

get a blocks insert point on a sheet

[ Edited ]

 

How can I determine a blocks insertion point on a sheet?  When I select a block and click Properties, I can see (and edit) the blocks insertion point on the sheet... How can I get this programmatically?  All I've gotten so far seems to be the block definition origin, which is identical for every block instance regardless of actual location on the sheet.  Here's what I've tried:

With objDocCurrent.Sections.WorkingSection.Sheets

    For i = 1 To .Count

       sheetName = .item(i).Name

       For j = 1 To .item(i).BlockOccurrences.Count

                'get the X and Y coords of the current insert (set values BlockX and BlockY)

 

                'this just gets the block definition origin ??...

                Call .item(i).BlockOccurrences(j).Block.Views.item(1).GetOrigin(BlockX, BlockY)

                'same problem here...

                Call .item(i).BlockOccurrences(j).BlockView.GetOrigin(BlockX, BlockY)

       Next j

    Next i

End With

Using VB6; SE v20

 

Posted by: Jon Zaerr
Post date: 4/1/2010 2:23:12 PM

2 REPLIES

RE: get a blocks insert point on a sheet

[ Edited ]

Hi,

there is no direct functiont to get the insert point of a block occurrence on the sheet, I tested with SE ST2.

There is an enhancement request for this...

 

Here is my workaround:

 

Dim oRef As SolidEdgeFramework.Reference

Dim aMatrix(16) As Double

 

' Take any 2d Geometry in the block view (line2d, circle2d, ...) with count >0 (lines2d.count)

' or one of the BlockLabels

If oBlockOcc.BlockView.Lines2d.Count > 0 Then

Set oRef = oBlockOcc.MemberReference(oBlockOcc.BlockView.Lines2d.Item(1))

'else...

End If

If Not oRef Is Nothing Then

 

oRef.GetMatrix aMatrix ' this is a 4 x 4 transformation matrix

' get the Offset vector (z is allway 0)

x = aMatrix(12)

y = aMatrix(13)

Debug.Print ("Position: x=" & x & "/ y=" & y)

End If

 

Posted by: Juergen Boelter
Post date: 4/2/2010 10:57:25 PM

RE: get a blocks insert point on a sheet

[ Edited ]

 

 

Thanks, that was a big help!  That MemberReference step is totally new to me.  Since my blocks dont seem to have been defined at the origin, I added a step to include what seems to be the block definition coordinates.  Here is my final version.

 

Dim NewBlockOccurence As SolidEdgeDraft.BlockOccurrence 'a new revision description block

Dim BlockX As Double                'block insertion point X

Dim BlockY As Double                'block insertion point Y

Dim AttVal As String                'attribute value

Dim oRef As SolidEdgeFramework.Reference    'for revision desc block --> transfer to background

Dim aMatrix(16) As Double                   'for revision desc block --> transfer to background

Dim oBlockOcc As SolidEdgeDraft.BlockOccurrence 'for rev desc blk --> transfer to background

Dim bRef(10) As BlockRef                        'stores pertinant block data for each GMOrev attribute

...

'now check working section (all sheets) for revision description blocks.  move to background sheet.

With objDocCurrent.Sections.WorkingSection.Sheets

    For i = 1 To .Count

       sheetName = .item(i).Name

       For j = .item(i).BlockOccurrences.Count To 1 Step -1     'loop backward to allow deletions

            blockname = UCase(.item(i).BlockOccurrences.item(j).Block.Name)

            If UCase(blockname) = "GMOREV" Then

                'get the X and Y coords of the current insert. Per Jürgen Bölter 4/4/2010 (www.jasonNewell.net)

                'There is no direct function to get the insert point of a block occurrence on the sheet,

                'I tested with SE ST2.  Here is my workaround:

                ' Take any 2d Geometry in the block view (line2d, circle2d, ...) with count >0 (lines2d.count)

                Set oBlockOcc = .item(i).BlockOccurrences.item(j)

                If oBlockOcc.BlockView.Lines2d.Count > 0 Then

                    Set oRef = oBlockOcc.MemberReference(oBlockOcc.BlockView.Lines2d.item(1))

                End If

                If Not oRef Is Nothing Then

                    'get base offset of block definition (in meters)

                    Call .item(i).BlockOccurrences(j).BlockView.GetOrigin(BlockX, BlockY)

                    'generate xform matrix.  This is a 4 x 4 transformation matrix

                    oRef.GetMatrix aMatrix

                    'add the Offset vector to the block definition point

                    BlockX = BlockX + aMatrix(12)

                    BlockY = BlockY + aMatrix(13)

                    OutputDebugString " BlockX: " & BlockX & " BlockY: " & BlockY & vbCrLf

                Else

                    BlockX = 0: BlockY = 0

                End If

 

                For k = 1 To .item(i).BlockOccurrences.item(j).BlockLabelOccurrences.Count

                    'check the attribute label

                    AttVal = .item(i).BlockOccurrences.item(j).BlockLabelOccurrences.item(k).value

                    'set values for use after inserting the new block on the background sheet

                    bRef(k).fontName = .item(i).BlockOccurrences.item(j).BlockLabelOccurrences.item(k).Style.Font

                    bRef(k).fontHt = .item(i).BlockOccurrences.item(j).BlockLabelOccurrences.item(k).Style.Height

                    bRef(k).Val = AttVal

                Next k

 

                'create new occurence on background sheet and copy attributes to it

                Set NewBlockOccurence = objDocCurrent.Sections.BackgroundSection.Sheets.item(GMOsheetID).BlockOccurrences.Add("GMOREV", BlockX, BlockY, , 1, 0)

                For k = 1 To .item(i).BlockOccurrences.item(j).BlockLabelOccurrences.Count

                    NewBlockOccurence.BlockLabelOccurrences.item(k).value = bRef(k).Val

                    NewBlockOccurence.BlockLabelOccurrences.item(k).Style.Font = bRef(k).fontName

                    NewBlockOccurence.BlockLabelOccurrences.item(k).Style.Height = bRef(k).fontHt

                Next k

 

                oBlockOcc.Delete        'delete the "from" block

 

                Set NewBlockOccurence = Nothing

                Set oBlockOcc = Nothing

                Set oRef = Nothing

 

            End If

       Next j

    Next i

End With

 

Posted by: Jon Zaerr
Post date: 4/5/2010 11:03:16 AM