abraxus Posted August 29, 2013 Share Posted August 29, 2013 (edited) i cant believe i have spent as much time already as i have trying to find a solution to such a simple problem - the code i am about to post explains itself, i hope - i am trying to iterate thru the block references collection in VBA, so that i can process a set of code (the code is irrelevant as i already know how to do that part) here's the simple code i am trying to use, and it wont even start the loop so i must have something defined wrong please explain what part i am not comprehending (it's all modelspace, no layoutspace) i hope this website emails me when people reply... i've never posted here before and i'm not sure how this works Sub PW() Dim blkEndcap As AcadBlockReference ' iterate thru a list of blocks named "fixture_block" and also have ScaleX set to 15 and ScaleY set to 5 For Each blkEndcap In ThisDrawing.Blocks If blkEndcap.Name = "fixture_block" And blkEndcap.ScaleX = 15 And blkEndcap.ScaleY = 5 Then debug.print "found one" End If Next End Sub Edited August 29, 2013 by abraxus Quote Link to comment Share on other sites More sharing options...
abraxus Posted August 29, 2013 Author Share Posted August 29, 2013 i'm probably going to have to wait at least 24 hours for a helpful reply, arent i... damn it - i wanted to get this done tonight Quote Link to comment Share on other sites More sharing options...
SEANT Posted August 29, 2013 Share Posted August 29, 2013 It's been awhile since using VBA, but try this: Dim AENT As AcadEntity Dim blkEndcap As AcadBlockReference For Each AENT In ThisDrawing.ModelSpace If TypeOf AENT Is AcadBlockReference Then Set blkEndcap = AENT If blkEndcap.Name = "fixture_block" And And blkEndcap.ScaleX = 15.0 And blkEndcap.ScaleY = 5.0 Then debug.print "found one" End If End If Next AENT Quote Link to comment Share on other sites More sharing options...
SEANT Posted August 29, 2013 Share Posted August 29, 2013 Though, I should mention - if the block reference in question is a dynamic block then you will have to use AcadBlockReference.EffectiveName Quote Link to comment Share on other sites More sharing options...
abraxus Posted August 29, 2013 Author Share Posted August 29, 2013 that helped... but i still cannot seem to reference the scale part - here's how i broke it down Sub pw3() Dim AENT As AcadEntity Dim blkEndcap As AcadBlockReference For Each AENT In ThisDrawing.ModelSpace If TypeOf AENT Is AcadBlockReference Then Set blkEndcap = AENT If blkEndcap.Name = "fixture_block" Then If blkEndcap.ScaleX = 15# Then If blkEndcap.ScaleY = 5# Then Debug.Print "found one" End If End If End If End If Next AENT End Sub Quote Link to comment Share on other sites More sharing options...
abraxus Posted August 29, 2013 Author Share Posted August 29, 2013 and thank you so much for at least giving me something to go on Quote Link to comment Share on other sites More sharing options...
SEANT Posted August 29, 2013 Share Posted August 29, 2013 Try: If blkEndcap.XScaleFactor = 15# Then Quote Link to comment Share on other sites More sharing options...
abraxus Posted August 29, 2013 Author Share Posted August 29, 2013 OMG thank you - that worked the documentation is horrible when trying to google things like this thank you thank you thank you thank you thank you Quote Link to comment Share on other sites More sharing options...
SEANT Posted August 30, 2013 Share Posted August 30, 2013 You're welcome. I'm happy you are up and running. AutoCAD used to come with a fairly good VBA reference. I think it was removed back when Autodesk planned on eliminating the VBA customization option. Look around on Autodesk.com, it may still be available for download. Quote Link to comment Share on other sites More sharing options...
abraxus Posted August 30, 2013 Author Share Posted August 30, 2013 oh i know they removed it from the default install, because it can be abused like any other VBA code which leads me to another question that you probably wont be able to answer, due to the complexity of corporate network administration, but when i write VBA code for autocad on my home computer, it works just fine, but when i try to run it at work, i get a weird error (i forget what it was, but i can write it down tomorrow and explain it if you might be able to help me with that too) - i'm guessing it's related to windows 7 and maybe some network restrictions, or registry restrictions or something... all i'm doing in the code that has the problem is trying to create VBA code that sets up some dimension variables, but it's like i dont have "permission" to change those variables with VBA code... any ideas? if not, that's cool... you already helped me get past the stupid issue i was having *puts on coder hat* Quote Link to comment Share on other sites More sharing options...
abraxus Posted August 30, 2013 Author Share Posted August 30, 2013 in short, it errors out on this line of code ' set dimension variables ThisDrawing.SetVariable "DIMCLRD", FDS_DIMCLRD do i need some sort of admin permissions to set variables in "ThisDrawing"? (it's not an error in variable declaration, because it works just fine with the same file on my home computer) Quote Link to comment Share on other sites More sharing options...
SEANT Posted August 30, 2013 Share Posted August 30, 2013 I haven't heard anything specific regarding network restriction. That particular variable is saved in the drawing, so it shouldn't even be flagged by some corporate policy concerning Registry modification on your work computer. Unfortunately, I can't look into it in any detail as I no longer have access to a computer with VBA installed. If you do figure out the problem, be sure to post a follow up. Quote Link to comment Share on other sites More sharing options...
abraxus Posted August 30, 2013 Author Share Posted August 30, 2013 i will, thanks again Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.