Results 1 to 5 of 5

Thread: Insert Block Using Named View's Center

  1. #1
    Member
    Join Date
    2009-09
    Posts
    2
    Login to Give a bone
    0

    Default Insert Block Using Named View's Center

    I am trying to use VBA code to insert different blocks with their insertion point being based upon the center of a named view. I can insert a block with a hard coded insertion point fine, and I have previous named views created by using the view manager to select the boundaries of my pre-drawn rectangles. My problem is apparently I don't understand how the named view centers work.

    UCS coordinates are world.
    This is all being done in modelspace.
    I already have about forty rectangles (size "32x18") set up in modelspace and each rectangle has a named view: Sheet1, Sheet2,......, Sheet40

    Goal:
    Insert block ABC with the insertion point of named view Sheet1's actual center, insert block XYZ with the insertion point of named view Sheet2's actual center, so on and so forth....
    The reference point could be the top left corner of the named view for all I care, I just want static point that is at the same reference location for each named view.

    Confusion:
    If was to start a line from the center of Sheet1's rectangle it has an actual center location of 17.9556, 9.1380. If I look at the properties of the named view Sheet1, it has the center point of -457.8247, -3.4866. Huh?

    I tried with code to change Sheet1's center point to the actual center of the rectangle, and it total changed where the view references. I would think that the center of the view would be the center of the boundaries selected.

    I see that there is Camera and Target properties of named views, but google can't seem to answer the differences between them and the center property.

    Long story short:
    How can I insert a block into a named view's reference point, where the reference point is the actual center of the view?

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,396
    Login to Give a bone
    0

    Default Re: Insert Block Using Named View's Center

    Welcome to AUGI. Post your code so we can help you. In the reply window, click on Go Advanced and use the code tags button to wrap your code.
    C:> ED WORKING....

  3. #3
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    555
    Login to Give a bone
    0

    Default Re: Insert Block Using Named View's Center

    If you look at the "view" using a bit of lisp the centre is assoc 10

    Code:
    (setq tab (tblnext "view" T))
    ((0 . "VIEW") (2 . "view1") (70 . 0) (40 . 302.94) (10 210.0 148.5) (41 . 723.610236966825) (11 0.0 0.0 1.0) (12 0.0 0.0 0.0) (42 . 50.0) (43 . 0.0) (44 . 0.0) (50 . 0.0) (71 . 0) (72 . 1) (110 0.0 0.0 0.0) (111 1.0 0.0 0.0) (112 0.0 1.0 0.0) (79 . 0) (79 . 0) (146 . 0))
    so closer to VBA using VL exposes property centre

    Code:
    (vlax-dump-object (vlax-ename->vla-object (tblobjname "VIEW" "view1")))
    
    ;
    ; Property values :
    ;
    ;   Application (RO) = #<VLA-OBJECT IAcadApplication 000000002C20C400>
    ;   CategoryName = ""
    ;   Center = (210.0 148.5)
    ;   Name = "view1"

  4. #4
    Member
    Join Date
    2009-09
    Posts
    2
    Login to Give a bone
    0

    Default Re: Insert Block Using Named View's Center

    FYI, I am using Excel VBA to manipulate CAD. If you are using this only in AutoCAD VBA direct, change "acad" in the code to "ThisDrawing".
    Code for changing view's center:
    Code:
    Public acad As AcadApplication
    Public acadDoc As AcadDocument
    
    Sub EditViewCenter()
    Dim viewObj As AcadView
    Dim ctr(1) As Double
    
    '*******************************************************************************
    'If using VBA directly in AutoCAD, remove this little section here.  This is for using Excel VBA with AutoCAD.
    On Error Resume Next
    Set acad = GetObject(, "AutoCAD.application")
    If Err <> 0 Then
        Err.Clear
        Set acad = CreateObject("AutoCAD.application")
        If Err <> 0 Then
            MsgBox "Could not start AutoCAD", vbExclamation
            End
        End If
    End If
    acad.Visible = True
    
    'Set the name of the opened drawing.
    Set acadDoc = acad.Documents.Item("Create Layouts.dwg")
    '*******************************************************************************
    
    'Item 0 is for the named view Sheet1.
    'I would like figure out how to use the actual name "Sheet1" in referencing the named view, but that's for another day..... baby steps.....
    'Right now using Views.Item(0) works.
    Set viewObj = acadDoc.Views.Item(0)
    
    'Assign Center X and Y values to the actual center coordinates of the rectangle for the named view.
    ctr(0) = 17.9556
    ctr(1) = 9.138
    
    'Update named view's center
    viewObj.center = ctr
    
    End Sub
    This changes the view's center value to the actual center of the rectangle, but when I do that it changes the view's actual location to some other place inside the drawing. The named view is no longer around the rectangle previously selected.

    Code for inserting block referencing the named view's center:

    Code:
    Sub CreateDIcenterView()
    Dim insertionPoint(2) As Double
    Dim acadBlockRef As AcadBlockReference
    Dim blockName As String
    Dim viewObj As AcadView
    
    Set viewObj = acadDoc.Views.Item(0)
    
    blockName = "DI"
    
    'Assign insertion point of block from the named view's center
    insertionPoint(0) = viewObj.Center(0)
    insertionPoint(1) = viewObj.Center(1)
    insertionPoint(2) = 0
    
    Set acadBlockRef  = acadDoc.ModelSpace.InsertBlock(insertionPoint, blockName, 1, 1, 1, 0)
    
    End Sub
    So..... back to my original questions:
    Why does is the center of the named view not the actual center of the rectangle selected?
    Why does changing the center of the named view to the actual center of the rectangle change the location of the named view?
    Should I be using something different like the camera or target variables?

  5. #5
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,396
    Login to Give a bone
    0

    Default Re: Insert Block Using Named View's Center

    Are you trying to insert the block at View.Center or change/create a view? Naturally, if you change the view's center you will change the projection of the view.
    C:> ED WORKING....

Similar Threads

  1. Replies: 4
    Last Post: 2017-10-11, 10:57 PM
  2. Insert a new block using data from existing block
    By mike.43789 in forum AutoLISP
    Replies: 3
    Last Post: 2015-01-12, 11:50 PM
  3. Replies: 5
    Last Post: 2013-12-20, 04:54 PM
  4. Routine to create named View for Block insert
    By cad user in forum AutoLISP
    Replies: 5
    Last Post: 2006-09-29, 03:38 AM
  5. named view label block
    By jkipfer in forum AutoCAD Sheet Set Manager
    Replies: 4
    Last Post: 2005-07-21, 11:33 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •