Author Topic: Capturing Named Views in Sset  (Read 13234 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
Capturing Named Views in Sset
« on: May 05, 2008, 10:55:22 AM »
Hi

I have a drawing with about 73 named views.
I am working on some code here;
With some help (Thanks Bob!)

This part is working well
Code: [Select]
For Each Ent In Sset
 If TypeOf Ent Is AcadBlockReference Then
 Set BlkRef = Ent
 strName = BlkRef.Name
 ThisDrawing.SendCommand "MSLIDE c:\tempslide\" & strName & vbCr
  '*****MAKE SURE THE ABOVE FOLDER EXISTS*****
 End If
Next Ent

And all it is doing is grabbing each blkref (1 per view) in the drawing and making a slide for each one, using the blkfef.name as the slide name

However, I want to be able to grab the lower left and upper right points of each view in the drawing as the pick points for each slide. I have the below code written, I am getting prompted for each point, the view is getting zoomed to window which is critical for this but I can not get the views to be recognized as an entity type in the sset or  I am likely doing something wrong.

The other problem I am having is that by using the for each loop, I am ending up with a slide show.

All I want to do is to be prompted for each view, pick my points, then have the code assign the blockref name for that view as the name of each slide, then return the view back to the previous view and prompt for the next selection.

Also, with the views, each one needs to be restored (-view, r etc) in order for the frozen (views) layer state to be used.

Hope this makes sense?

Thanks!

M

Code: [Select]
Dim NView As AcadView
Dim Sset As AcadSelectionSet
Dim Ent As AcadEntity
Dim Pnt1 As Variant
Dim Pnt2 As Variant

Pnt1 = ThisDrawing.Utility.GetPoint(, "Pick First Point")
Pnt2 = ThisDrawing.Utility.GetPoint(, "Pick Second Point")

Set Sset = ThisDrawing.SelectionSets.Add("Sset")
Sset.Select acSelectionSetWindow, Pnt1, Pnt2
ZoomWindow Pnt1, Pnt2

For Each Ent In Sset
 If TypeOf Ent Is AcadView Then
  strName = NView.Name
  ThisDrawing.SendCommand "-view" & vbCr & "r" & vbCr & strName & vbCr
  End If
Next Ent




ML

  • Guest
Re: Capturing Named Views in Sset
« Reply #1 on: May 05, 2008, 11:12:23 AM »

Ok,
With this code, I am almost have what I need

Code: [Select]
Sub CreateSlides()
  On Error Resume Next
  ThisDrawing.SelectionSets.Item("Sset").Delete
 
  Dim Sset As AcadSelectionSet
  Dim Ent As AcadEntity
  Dim BlkRef As AcadBlockReference
  Dim NView As AcadView
   
  Dim strName As String
  Dim VName As String
  Dim sysFileDia As Integer
     
  Dim Pnt1 As Variant
  Dim Pnt2 As Variant
   
  Pnt1 = ThisDrawing.Utility.GetPoint(, "Pick First Point")
  Pnt2 = ThisDrawing.Utility.GetPoint(, "Pick Second Point")
     
  Set Sset = ThisDrawing.SelectionSets.Add("Sset")
  Sset.Select acSelectionSetWindow, Pnt1, Pnt2
  ZoomWindow Pnt1, Pnt2
 
  sysFileDia = ThisDrawing.GetVariable("FILEDIA")
  ThisDrawing.SetVariable "FILEDIA", 0
   
  For Each Ent In Sset
   If TypeOf Ent Is AcadView Then
    VName = NView.Name
    GoTo Continue
   End If
  Next Ent
 
Continue:
  For Each Ent In Sset
   If TypeOf Ent Is AcadBlockReference Then
    Set BlkRef = Ent
    strName = BlkRef.Name
    ThisDrawing.SendCommand "-view" & vbCr & "r" & vbCr & VName & vbCr
    ThisDrawing.SendCommand "MSLIDE c:\tempslide\" & strName & vbCr
   '*****MAKE SURE THE ABOVE FOLDER EXISTS*****
    End If
  Next Ent
  ThisDrawing.SetVariable "FILEDIA", sysFileDia
End Sub

Except it is still asking me what view I would like to restore; I am not sure how to pass that in, so when I do vslide, the slide is still showing the view and construction lines, I just want to see the blkref.

And at the end, I would like to restore the view to previous.

Can anyone get me over this last huddle?

Thanks
M

Bob Wahr

  • Guest
Re: Capturing Named Views in Sset
« Reply #2 on: May 05, 2008, 12:51:35 PM »
Hadn't abandoned you, just busy.

Give this a look, needs to have the directory selection and text file bits added in.

Code: [Select]
Option Explicit
Sub MLides()
Dim objView As AcadView
Dim objViews As AcadViews
Dim varViewCen As Variant
Dim dblHgt As Double
Dim dblWdt As Double
Dim dblLLPt(0 To 2) As Double
Dim dblURPt(0 To 2) As Double
Dim objEnt As AcadEntity
Dim objBlkRef As AcadBlockReference
Dim objSelSet As AcadSelectionSet
Dim objSelSets As AcadSelectionSets
Dim strSldName As String

Set objViews = ThisDrawing.Views
For Each objView In objViews
  varViewCen = objView.Center
  dblHgt = objView.Height
  dblWdt = objView.Width
  dblLLPt(0) = varViewCen(0) - (dblWdt / 2)
  dblLLPt(1) = varViewCen(1) - (dblHgt / 2)
  dblLLPt(2) = 0
  dblURPt(0) = varViewCen(0) + (dblWdt / 2)
  dblURPt(1) = varViewCen(1) + (dblHgt / 2)
  dblURPt(2) = 0
  ZoomWindow dblLLPt, dblURPt
       
  Set objSelSet = ThisDrawing.SelectionSets

  For Each objSelSet In objSelSets
    If objSelSet.Name = "blkpick" Then
      ThisDrawing.SelectionSets.Item(strSet).Delete
    Exit For
    End If
  Next
  Set objSelSet = objSelSets.Add("blkpick")
  objSelSet.Select acSelectionSetWindow, dblllpnt, dblurpnt
  For Each objEnt In objSelSet
    If TypeOf objEnt Is AcadBlockReference Then
      Set objBlkRef = objEnt
      strSldName = objBlkRef.Name
      Exit For
    End If
  Next objEnt
  ThisDrawing.SendCommand "MSLIDE c:\tempslide\" & strSldName & vbCr
Next objView
   
   
Next objView
End Sub


Bob Wahr

  • Guest
Re: Capturing Named Views in Sset
« Reply #3 on: May 05, 2008, 01:52:34 PM »
Don't forget to change filedia.  I just did the views bit quickly and without testage, then flopped bits of the other stuff in.  Will definitely take some up cleanage.

ML

  • Guest
Re: Capturing Named Views in Sset
« Reply #4 on: May 05, 2008, 02:08:12 PM »

Hey Bob

I appreciate this

I had an idea that the center, height and width methods were the ticket but I was not making progress with it so I tried to change up.

Anyhow, I can see from trying the code that you posted that it is "going" to work; that is super cool!

It is creating the slides but not in the right directory, I am working on that part now, and I just put the filedia code in.

Also, at the end, I just put zoomprevious

So, let me see what I can do here

Mark

ML

  • Guest
Re: Capturing Named Views in Sset
« Reply #5 on: May 05, 2008, 03:21:33 PM »

Bob

I'm still having a problem making this work properly but I thought of one thing
Why do I need to restore each view?
How about if I just freeze the layer that all of the views are on in the beginning of the module? DUHHHH
That should work.


Bob, this is the error that is getting generated
Quote
Command: MSLIDE
Enter name of slide file to create <K:\AutoCAD\Work
Related\SlideTemplate-Labls-test>: c:\tempslide\AUTHORIZ_LT
C:\tempslide\AUTHORIZ_LT.sld already exists, do you want to replace it?
[Yes/No] <N>:
Document "K:\AutoCAD\Work Related\SlideTemplate-Labls-test.dwg" has a command
in progress.

Do you see where I am going wrong?
Also, I am not really sure that we need to even write out the list of blocknames; I could be wrong.
If we were creating a slide library from DOS using slidelib, then we would absolutely need that txt file

Here is the code so far:
Code: [Select]
On Error Resume Next
ThisDrawing.SelectionSets.Item("blkpick").Delete

Dim objView As AcadView
Dim objViews As AcadViews
Dim varViewCen As Variant
Dim dblHgt As Double
Dim dblWdt As Double
Dim dblLLPt(0 To 2) As Double
Dim dblURPt(0 To 2) As Double
Dim objEnt As AcadEntity
Dim objBlkRef As AcadBlockReference
Dim objSelSet As AcadSelectionSet
Dim objSelSets As AcadSelectionSets
Dim intFile As Integer
Dim strFileName As String
Dim strSldName As String
Dim sysFileDia As Integer

sysFileDia = ThisDrawing.GetVariable("FILEDIA")
ThisDrawing.SetVariable "FILEDIA", 0

Set objViews = ThisDrawing.Views
For Each objView In objViews
  varViewCen = objView.Center
  dblHgt = objView.Height
  dblWdt = objView.Width
  dblLLPt(0) = varViewCen(0) - (dblWdt / 2)
  dblLLPt(1) = varViewCen(1) - (dblHgt / 2)
  dblLLPt(2) = 0
  dblURPt(0) = varViewCen(0) + (dblWdt / 2)
  dblURPt(1) = varViewCen(1) + (dblHgt / 2)
  dblURPt(2) = 0
  ZoomWindow dblLLPt, dblURPt
       
  Set objSelSets = ThisDrawing.SelectionSets
  Set objSelSet = objSelSets.Add("blkpick")
 
  objSelSet.Select acSelectionSetWindow, dblLLPt, dblURPt
     
  For Each objEnt In objSelSet
    If TypeOf objEnt Is AcadBlockReference Then
      Set objBlkRef = objEnt
      strSldName = objBlkRef.Name
      Exit For
    End If
  Next objEnt
  ThisDrawing.SendCommand "MSLIDE c:\tempslide\" & strSldName & vbCr
  strFileName = "C:\tempslide\" & ThisDrawing.GetVariable("dwgname") & ".lst"
  '*****MAKE SURE THIS FOLDER EXISTS*****
      intFile = FreeFile
      Open strFileName For Append As #intFile
      Print #intFile, strSldName & ".sld"
      Close #intFile
 Next objView
  ThisDrawing.SetVariable "FILEDIA", sysFileDia
  ZoomPrevious

Thanks
Mark

ML

  • Guest
Re: Capturing Named Views in Sset
« Reply #6 on: May 05, 2008, 03:30:52 PM »

OK

Good and bad news
The good news is that I was not seeting the filedia correctly.
I fixed that and all of the slides got created
However, freezing the layer was not a good idea after all
If I did that, then what points are getting picked? DUHHH

So, if you can help me get each view to restore prior to the points getting picked, then I would say, it is a definite go
If I get some time here, I will try again as well

You definitely got the loop part working perfect

Mark

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Capturing Named Views in Sset
« Reply #7 on: May 05, 2008, 03:36:51 PM »
the points are being generated from the width and height of the view
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

ML

  • Guest
Re: Capturing Named Views in Sset
« Reply #8 on: May 05, 2008, 04:35:00 PM »
Yes, I know
So, you wouldn't think that freezing the layer would effect anything, right?
There is definitely a noticeable difference when you do a manual mslide and when you run this code with the layer frozen.
I'm not sure what the problem is.

I was thinking that may be I need to get rid of the zoomwindow part of the code?

If we use a zoomwindow, we would need something on screen to be picked, wouldn't we?

I would love to just freeze the layer and be done but the slides are not coming out with the height and width sizes.

I didn't really look close enough at Bob's code, I am assuming the math is correct

Mark

Bob Wahr

  • Guest
Re: Capturing Named Views in Sset
« Reply #9 on: May 05, 2008, 04:56:25 PM »
Yes, I know
So, you wouldn't think that freezing the layer would effect anything, right?
There is definitely a noticeable difference when you do a manual mslide and when you run this code with the layer frozen.
I'm not sure what the problem is.

I was thinking that may be I need to get rid of the zoomwindow part of the code?

If we use a zoomwindow, we would need something on screen to be picked, wouldn't we?

I would love to just freeze the layer and be done but the slides are not coming out with the height and width sizes.

I didn't really look close enough at Bob's code, I am assuming the math is correct

Mark

The layer being frozen has nothing to do with anything.  It's possible that the views that you have saved are different than a window based off of your rectangles.  I haven't checked and don't have time right now to do so.  I'll try this one one more time...I've said it several times and other people have as well.  Step through your code line by line and see what's happening.  When the code I posted zooms a windows based off of view "1", does the screen look the same as if you manually restore the view?

If you get rid of the zoomwindow part of the code, what will happen?  Hint, mslide make a slide of the current display.  If you don't change the current display and make a slide, what do you get?  If you don't change it again, and make another slide, what do you get?

Maverick®

  • Seagull
  • Posts: 14778
Re: Capturing Named Views in Sset
« Reply #10 on: May 05, 2008, 08:19:51 PM »
And now back for your posting pleasure.....  *ding ding*

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Capturing Named Views in Sset
« Reply #11 on: May 05, 2008, 08:22:28 PM »
I'm not saying nuttin till I see my lawyer.

Glenn R

  • Guest
Re: Capturing Named Views in Sset
« Reply #12 on: May 06, 2008, 03:59:28 AM »
Was there any particular reason posts were removed from this thread?

hendie

  • Guest
Re: Capturing Named Views in Sset
« Reply #13 on: May 06, 2008, 05:03:21 AM »
am I correct in thinking that you have a named view for each block ?
Rather than messing about with named views, wouldn't it be easier to create a selection set of all blocks then loop through the selection set getting the bounding box of each block, and using those coordinates as your zoom window, then do the mslide thing ?

Code: [Select]
While X < SSet1.Count
    For Each Xblk In SSet1
                       
        Inspt = Xblk.InsertionPoint
       
        Dim Zcenter(0 To 2) As Double
            Zcenter(0) = Inspt(0): Zcenter(1) = Inspt(1): Zcenter(2) = Inspt(2)
                                            Dim BboxSP As Variant
        Dim BboxEP As Variant
            Xblk.GetBoundingBox BboxSP, BboxEP
        Dim BboxP1(0 To 2) As Double
        Dim BboxP2(0 To 2) As Double
            BboxP1(0) = BboxSP(0): BboxP1(1) = BboxSP(1): BboxP1(2) = BboxSP(2)
            BboxP2(0) = BboxEP(0): BboxP2(1) = BboxEP(1): BboxP2(2) = BboxEP(2)
            ZoomWindow BboxP1, BboxP2
             
              ' DO THE MSLIDE BIT HERE
         
    Next Xblk
    X = X + 1
Wend

ML

  • Guest
Re: Capturing Named Views in Sset
« Reply #14 on: May 06, 2008, 10:06:10 AM »

Hey Hendie

Yes, that would make perfect sense and Bob had provided some good code to do just that but the problem seems to be that the bounding box doesn't give you enough space around the block and the slide doesn't come out as well; the block tends to get too close to the edges of the slide. If there were a way to increase the bounding box size, that would be great.

Initially with code Bob supplied, I was able to grab the center of each bounding box which really helped position the blocks into place; that was a big time saver but for this particular thing, I think that I would prefer to pick points.

I think I will just go back to my initial thought and that was to make a simple pick 2 points, then have the slide name = the blkref name.

I really don't have a problem grabbing a few points for each slide, it is typing the names for each that I can live without.

Thanks Hendie, I will still look at your code.

Mark