TheSwamp

Code Red => VB(A) => Topic started by: Matersammichman on June 30, 2006, 09:49:57 AM

Title: REMOVING EXISTING HYPERLINKS
Post by: Matersammichman on June 30, 2006, 09:49:57 AM
I'm using VB6 to open CAD drawings and want to remove existing Hyperlinks from the dwgs. I can make this work in VBA, but not pure VB.
Help? :lol:
Title: Re: REMOVING EXISTING HYPERLINKS
Post by: DaveW on June 30, 2006, 10:37:11 AM
Do you have sucessful vb6 projects working?

Are you making an activex dll? If so, how are you linking to it?

Your info is lacking. :)

Post some code.

Also, if you need help setting up a pure vb project, take a look at this:
http://www.websitetoolbox.com/tool/post/milllister/vpost?id=1071084&trail=30#1

You can go back to the http://milllister.com/ page and grab my phone and call me if you need help debuging in design time.
Title: Re: REMOVING EXISTING HYPERLINKS
Post by: Matersammichman on June 30, 2006, 11:07:50 AM
Here's what I tried...

Dim ACADHYPERLINK As Object
Set ACADHYPERLINK = acadDoc.ACADHYPERLINK
For Each ACADHYPERLINK In acadDoc
ACADHYPERLINK.Delete
Next ACADHYPERLINK

...needless to say, it didn't work.
Title: Re: REMOVING EXISTING HYPERLINKS
Post by: Bob Wahr on June 30, 2006, 11:32:52 AM
nope it didn't.  give this a shot, will probably require some tweakage.
Code: [Select]
Sub test()
Dim objHL As AcadHyperlink
Dim objHLs As AcadHyperlinks
Dim objThingy As AcadEntity
For Each objThingy In acadDoc.PaperSpace
  If objThingy.Hyperlinks.Count <> 0 Then
    Set objHLs = objThingy.Hyperlinks
    For Each objHL In objHLs
      objHL.Delete
    Next objHL
  End If
Next objThingy
For Each objThingy In acadDoc.PaperSpace
  If objThingy.Hyperlinks.Count <> 0 Then
    Set objHLs = objThingy.Hyperlinks
    For Each objHL In objHLs
      objHL.Delete
    Next objHL
  End If
Next objThingy

End Sub
That was VBA done then thisdrawing was changed to acaddoc so you will have to set acaddoc, etc.
Title: Re: REMOVING EXISTING HYPERLINKS
Post by: Bob Wahr on June 30, 2006, 11:43:57 AM
Here's what I tried...

Dim ACADHYPERLINK As Object
Set ACADHYPERLINK = acadDoc.ACADHYPERLINK
For Each ACADHYPERLINK In acadDoc
ACADHYPERLINK.Delete
Next ACADHYPERLINK

...needless to say, it didn't work.
Just for the understanding side of it, the reason that won't work is that what you are telling VB is that it's going to iterate through everything in the drawing AND that everything in the drawing that it will find is a hyperlink.  The first thing it gets to that isn't a hyperlink, the program says, "Hey, this isn't a hyperlink you.  I think I'm going to toss the binky." 

The only time that code would work is if you had a drawing that contained absolutely nothing but hyperlinks which won't ever ever happen for two reasons.

1) paperspace and modelspace are both blocks and you can't get rid of them.
2) you can't have a hyperlink in a drawing.  Hyperlinks are attached to objects, not objects in their own right.

Make sense?
Title: Re: REMOVING EXISTING HYPERLINKS
Post by: Matersammichman on June 30, 2006, 12:48:44 PM
Bob,
I am on VB6 Learning Edition...

I tried your code, but VB6 isn't recognizing "Dim objHL As AcadHyperlink". It gives me an error, "user-defined type not defined". What else do I need to do?

Dave,
Constructive criticim is always welcome...Good code is always welcome too.
I'm a newb at using VB6 to access Cad.
Title: Re: REMOVING EXISTING HYPERLINKS
Post by: Chuck Gabriel on June 30, 2006, 01:03:41 PM
Sounds like you need to add a reference to the AutoCAD type library.

Also, if you iterate over the database like below, it will get any links embedded in blocks in addition to the ones in modelspace and paperspace.

Code: [Select]
Sub removeHyperLinks(ByRef doc As AcadDocument)
  Dim block As AcadBlock
  For Each block In doc.Blocks
     Dim ent As AcadEntity
     For Each ent In block
      Dim links As AcadHyperlinks
      Set links = ent.hyperLinks
      If links.Count <> 0 Then
        Dim link As AcadHyperlink
        For Each link In links
          link.Delete
        Next link
        Set link = Nothing
      End If
     Next ent
     Set ent = Nothing
  Next block
  Set block = Nothing
End Sub
Title: Re: REMOVING EXISTING HYPERLINKS
Post by: Glenn R on June 30, 2006, 09:49:33 PM
Chuck wins!

Exactly how I would have done it Chuck - like minds and all the rest of it...;)

Cheers,
Glenn.
Title: Re: REMOVING EXISTING HYPERLINKS
Post by: Chuck Gabriel on July 01, 2006, 03:35:44 PM
Exactly how I would have done it Chuck - like minds and all the rest of it...;)

Twins separated at birth perhaps?  You don't, by chance, have one leg shorter than the other and a large back hump, do you?  :-D
Title: Re: REMOVING EXISTING HYPERLINKS
Post by: Kerry on July 01, 2006, 07:35:19 PM
:lol:

If you enjoy bourbon Chuck, that clinches it for me.
Title: Re: REMOVING EXISTING HYPERLINKS
Post by: Glenn R on July 01, 2006, 09:09:30 PM
Probably triplets with that comment brother Kerry ;)