Jump to content

xref clip boundry


cadman6735

Recommended Posts

Yup.

 

I was going to correct you on your GetXRefs, but I just noticed you made the necessary modification.

 

lol - thanks - spotted it just in time... vlax-for doesn't act like you would expect :(

 

Lol, made me think of this :P

 

duty_calls.png

Link to comment
Share on other sites

  • Replies 59
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    20

  • cadman6735

    17

  • BlackBox

    15

  • alanjt

    8

Top Posters In This Topic

Posted Images

lol - thanks - spotted it just in time... vlax-for doesn't act like you would expect :(

It's not vlax-for that was the problem, it was your if statement, it would have only worked if the last object checked was an XRef.

 

eg.

(setq l (vl-sort (vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
                  (setq l (cons (vla-get-name x) l))
                )
                '<
       )
)

Link to comment
Share on other sites

It's not vlax-for that was the problem, it was your if statement, it would have only worked if the last object checked was an XRef.

 

Oh true

 

(defun GetXRefs ( / l )
 (reverse
   (vlax-for block
     (vla-get-Blocks
       (vla-get-ActiveDocument
         (vlax-get-acad-object)
       )
     )
     (if (eq :vlax-true (vla-get-isXref block))
       (setq l (cons block l))
       l
     )
   )
 )
)

 

Or I suppose:

 

(defun GetXRefs ( / l )
 (vlax-map-collection
   (vla-get-Blocks
     (vla-get-ActiveDocument
       (vlax-get-acad-object)
     )
   )
   (function
     (lambda ( block )
       (if (eq :vlax-true (vla-get-isXref block))
         (setq l (cons block l))
       )
     )
   )
 )
 (reverse l)
)

 

So many ways to skin the cat...

Link to comment
Share on other sites

I thank all, for your advise and guidence,

 

Lee

 

as the omission of these will only confuse a beginner

 

I am glad that this is understood that as a beginner I can get overwelmed and confussed. It takes time to digest and reconstruct code in my own way to understand what is going on but..

some where in here you stated that I should keep in mind that these are sub functions, which I recognize, but the omission of the main function is where I get lost. I don't know how to use the sub function yet. In my third post I stated

 

The only problem is, I don't know what to do with it:?

 

This is the part I don't know what to do with, How do I envoke the sub function, this is a missing piece for me.

 

 

I feel I should know more than I do or at least have some sort of vision of how to use it, but I am just not there yet.

Link to comment
Share on other sites

I tell ya what I do like

 

All the different ways to get something done (I don't understand them yet, but I do see new functions to study) and seeing them used gives me an idea of how and where to use them.

 

this is truely a great forum

Link to comment
Share on other sites

There is a lot of information out there about subfunctions, so I shan't reiterate it, but the basic notion of a subfunction is that you have a stand-alone function that may be supplied with arguments and produce a 'useful' return. As you can imagine, the possibilities are endless.

 

As a very simple example, say we want to perform a little arithmetic on a number many times within a main function, say:

 

(sqrt (+ (/ x 3.0) 5.0))

 

For some variable 'x'. To save us from re-typing this same line of code over and over, we can create a subfunction to house this section of code:

 

(defun DoMath ( x )
 (sqrt (+ (/ x 3.0) 5.0))
)

 

Now, we can call this from within out main function:

 

(defun DoMath ( x )
 (sqrt (+ (/ x 3.0) 5.0))
)

(defun c:test ( / n )

 (if (setq n (getreal "\nPick a number: "))
   (print (DoMath n))
 )

 (princ)
)

 

Notice how I pass the variable 'n' containing our numerical data to the subfunction 'DoMath', which subsequently returns an output, which we print.

 

Perhaps my example wasn't the best, so perhaps this is also worth a read:

 

http://www.theswamp.org/index.php?topic=34049.0

 

http://www.theswamp.org/index.php?topic=35059.0

 

Lee

Link to comment
Share on other sites

:: Regarding Omissions ::

 

I am glad that this is understood that as a beginner I can get overwelmed and confussed. It takes time to digest and reconstruct code in my own way to understand what is going on but..

some where in here you stated that I should keep in mind that these are sub functions, which I recognize, but the omission of the main function is where I get lost.

 

 

What Lee was pointing out (to me) was that the sub-functions I posted contained calls (a dependency) on other sub-functions that I've written. Without those Dependant sub-functions, my code would not work.

 

My code would be more easily understood (and helpful to you) if I were to (a) include the sub-function's code, or (b) replace the sub-function with the actual code to make one cohesive routine.

 

You see I was (am?) a beginner, as of earlier this year. So I may overlook some of the refinements that you'll see from veteran developers like Lee, and Alan (mad props guys! :beer: ), etc.

 

Besides, I hate being 'confussed' just like the next guy. o:) lol

Link to comment
Share on other sites

Renderman

 

Sorry for jumping in and taking a quote directed at you and applying it to myself. I understand that Lee was talking to you and I was only making a point to Lee that I to am a beginner and by giving me a subfunction when I have not used one yet nor know how to pull the desired information from the sub function was my confusion from my 3rd post.

 

I got excited (in my own little warped world) that someone 'lee' (and most of you) I am sure, understand that beginners need extra insite (for the lack of a better word)...

 

I have trolled a lot of forums and most that I come across are ran by unhelpful know it alls that seem to talk down to the less experianced.

 

People here are very polite and helpful, I jumped into a converstation as one of the group, but I understand that I am still the new guy. I am here to learn not agrivate anyone.

Link to comment
Share on other sites

Sorry for jumping in and taking a quote directed at you and applying it to myself.

 

No worries Cadman.

 

I hope I've not made you feel like you've aggravated me (or anyone else) :unsure: , my friend.

 

I was simply trying to clarify the point, and certainly not get all territorial on you. If anything I was trying to point out a component of your confusion, was my mistake. :oops: Nothing more.

 

People here are very polite and helpful, I jumped into a converstation as one of the group, but I understand that I am still the new guy.

 

Respect is important, and kindness is always appreciated.

 

You're a 'Full Member' bud, and not some 'new guy'... besides, we're all here to learn, teach, or help. :)

Link to comment
Share on other sites

By the way, sorry if this seems petty, but I meant to pick up on it earlier, in your original code:

 

([color=blue][color=black]setq[/color][/color]acaddoc ([color=black]vlax-get-acad-object[/color]))

 

You use the variable 'acaddoc'. Although variable names are arbitrary, descriptive names are much easier to follow - however the VLA Object to which your variable points is not the acaddoc, but rather the application object (perhaps 'acadapp' may be a better name).

 

A brief overview of the ActiveX Object Model by Lee Mac

 

A complete diagrammatic overview of the Object Model can be found in the VLIDE (Visual LISP Integrated Development Environment) Help Files under:

 

+-- ActiveX and VBA Reference
|
+------ Object Model

ObjectModelLocation.png

 

This depicts all the VL Collections & Objects that one may access from the AutoCAD Application Object

 

Here is a small snippet of the model:

 

ObjectModelSnippet.png

 

Now lets do some investigation: in the VLIDE, go to the console (F6).

 

Before we do anything we've first got to load the Visual LISP extensions using:

 

([color=blue][b]vl-load-com[/b][/color])

So type this at the console and hit enter.

 

OK, so starting from the top, we can access the AutoCAD Application object using the code:

 

(setq [color=green][b]acapp [/b][/color]([color=blue][b]vlax-get-acad-object[/b][/color]))

Hitting enter you will see that 'acapp' now points to the Application VLA Object.

 

Each Object/Collection in the model has a set of properties and methods that we may use to manipulate that object/collection. We can query the properties of the object in a number of ways.

 

To query the properties and methods for the Application object for example, we can use the Object Model diagram and click on the 'Application' bubble.

 

Alternatively, we can use the vlax-dump-object function, so type:

 

([b][color=blue]vlax-dump-object[/color][/b] [b][color=green]acapp[/color][color=blue] t[/color][/b])

And hit enter.

 

All the properties (and their values) and methods will be listed for the application object - those marked (RO) are 'Read Only' can cannot be changed. Notice that the second argument ( 't' ) is supplied to the vlax-dump-object function to make sure that Methods are also listed.

 

To get information on this function or any other function for that matter, double click on the function (to highlight it) and click on the Help Speech bubble on the relevant toolbar; or, go to Help > Visual LISP Help Topics and search for the function.

 

Now, notice that some of the properties that appear listed for the Application object also appear in the Object Model. And this is exactly how we can retrieve these objects.

 

So, to get the ActiveDocument Object (i.e. the current drawing open), we use:

 


(setq [color=green][b]acdoc[/b][/color] ([color=blue][b]vla-get-ActiveDocument[/b][/color] [color=green][b]acapp[/b][/color]))

And again, we can query its properties and methods and see other objects that appear beneath it in the Object Model.

 

As a side note on properties and methods:

 

There are various ways to get a property, some utilising different data types, for example, because the AutoCAD type library is loaded when we use vl-load-com, we can access the properties of objects using a function with the property in the name (as in the example above):

 

([b][color=blue]vla-get-[/color][color=red]<Property-Of-Object>[/color][/b] [b][color=green]<object>[/color][/b])

However, this is also equivalent:

 

([color=blue][b]vlax-get-property[/b][/color] [b][color=green]<object>[/color][/b] [color=red][b]<Property-Of-Object>[/b][/color])

And hence, for our above example:

 

([color=blue][b]vlax-get-property[/b][/color] [b][color=green]acapp[/color][/b] '[b][color=red]ActiveDocument[/color][/b])

will return the same object.

 

This logic applies to modifying properties too, hence:

 

([color=blue][b]vla-put-[/b][/color][b][color=red]<Property-Of-Object>[/color][/b] [color=green][b]<Object>[/b][/color] [color=purple][b]<Property-Value>[/b][/color])

Is the same as:

 

([color=blue][b]vlax-put-property[/b][/color] [color=green][b]<Object>[/b][/color] [color=red][b]<Property-Of-Object>[/b][/color] [color=purple][b]<Property-Value>[/b][/color])

For example:

 

([color=blue][b]vla-put-[color=red]Height[/color][/b][/color] [color=green][b]acdoc [/b][/color][color=purple][b]100[/b][/color])

is the same as:

 

([color=blue][b]vlax-put-property[/b][/color] [color=green][b]acdoc [/b][/color]'[color=red][b]Height[/b][/color] [color=purple][b]100[/b][/color])

or

([color=blue][b]vlax-put-property[/b][/color] [color=green][b]acdoc [/b][/color]"[color=red][b]Height[/b][/color]" [color=purple][b]100[/b][/color])

Similarly with methods, we can use:

 

([color=blue][b]vla-[/b][/color][color=red][b]<Method-Of-Object>[/b][/color] [color=green][b]<Object>[/b][/color])

Or

 

([color=blue][b]vlax-invoke-method[/b][/color] [color=green][b]<Object>[/b][/color] [color=red][b]<Method-Of-Object>[/b][/color])

Both will act in the same way.

 

There are also the undocumented, vlax-get/put and vlax-invoke, but at risk of moving too far from the topic, I'll leave these for now - some brief info can be found here.

 

Back on Topic:

 

To get at other collections / objects, we just need to know where they are located on the hierarchy, hence, say we want to get the Blocks Collection.

 

Notice that the Blocks Collection is located beneath the Document Object in the hierarchy (and you can see that it is a property of the ActiveDocument Object), hence we can retrieve it as we would any other property:

 

([color=blue][b]vla-get-Blocks[/b][/color] [color=green][b]acdoc[/b][/color])

Or, showing the full hierarchy in practice:

 


([color=blue][b]vla-get-Blocks[/b][/color]
([color=blue][b]vla-get-ActiveDocument[/b][/color]
([color=blue][b]vlax-get-acad-object[/b][/color])
)
)

So, as you can hopefully see - there is a lot we can do with just the Object Model.

 

Any questions, or spot any mistakes - Shout.

 

Lee

Edited by Lee Mac
Link to comment
Share on other sites

Lee

 

Nothing is petty, I am looking for experiance to guide me the right way, I would rather get nit-picked now and learn good practice than develope bad habits.

 

They say "practice makes perfect", this is not true, only 'perfect practice make perfect'

 

If I am practicing the wrong way, I am still doing it wrong, just getting better at doing it wrong.

 

I do appriciate the little details, it all adds up.

 

 

I haven't gone thru your tutoral yet, I will try to get to it this weekend, I hope (got to go to Atlanta to pick up the mother-in-law to meet her new granddaughter (8 hour drive one way and I have to come back again)) :cry:

 

Thanks

Link to comment
Share on other sites

Great tutorial

 

I went thru it during my lunch...

 

One of the main things I am picking up on is the use of (vlax) vs. (vla)

 

It seems to me when accessing the object first, we use (vlax)

When accessing the property or method first, we use (vla)

 

So I am assuming that the (vlax) the 'x' only works with objects? and by assigning a property or method to a variable we are actualy creating an object?

Seeing the code written two different ways really helps with understanding of why and when to use (vla) or (vlax), so far.

 

Another thing I got from this is (I found the Object Model chart a few weeks ago) I was not aware I could click on the bubbles, helpful tip.

 

 

 

I discovered that the xrefs are located under "database" under Blocks. Please help me see how to access the xrefs.

 

Using a

 

 
(defun C:acxref ( / )
 (setq xreflist (........

 

No subfunctions, please. I am not at that level yet.

 

 

All I want (for now) is a list of xrefs to see what xrefs are in my drawing by typing !xreflist at the command prompt. And how to access the xref properties and methods... So I can start experimenting.

 

I don't really want to ask for someone to write code for me, but I am in need of an example to pass this hump.

 

Thanks

 

Edit...

 

I am looking at Blocks collection access via Document.Blocks.

 

It seems if I took the time to play I could figure it out. but too much info at one time, I am swimming in too much info and too eager to run before I can walk.

Link to comment
Share on other sites

One of the main things I am picking up on is the use of (vlax) vs. (vla)

 

It seems to me when accessing the object first, we use (vlax)

When accessing the property or method first, we use (vla)

 

So I am assuming that the (vlax) the 'x' only works with objects? and by assigning a property or method to a variable we are actualy creating an object?

 

 

While your deductive reasoning may 'seem' logical, young padawan, instead consider this small example:

 

Command: [color=red](setq textObj (vlax-ename->vla-object (car (entsel))))[/color]

Select object: [color=blue]#<VLA-OBJECT IAcadMText 0c64a1d4>[/color]

Command: [color=red](vla-get-insertionpoint textObj)[/color]
[color=blue]#<variant 8197 ...>[/color]

Command: [color=red](vlax-get textObj 'insertionpoint)[/color]
[color=blue](8.14151 16.7524 0.0)[/color]

 

 

Note the difference in returned output, for each method of accessing the InsertionPoint property.

 

Edit: Sorry, I was going to make a separate post, but it seemed more prudent to simply edit this post.

 

I discovered that the xrefs are located under "database" under Blocks. Please help me see how to access the xrefs.

 

Using a

 

 
(defun C:acxref ( / )
(setq xreflist (........

 

No subfunctions, please. I am not at that level yet.

 

 

All I want (for now) is a list of xrefs to see what xrefs are in my drawing by typing !xreflist at the command prompt. And how to access the xref properties and methods... So I can start experimenting.

 

I don't really want to ask for someone to write code for me, but I am in need of an example to pass this hump.

 

 

This has already been written for you. I did go back and remove the sub-functions at Lee's apt request, but to reiterate, here is it again, so you don't have to go back and find it among the lot:

 

I am looking for a way to list my xref blocks
Here is one way:

 

(defun i:xrefList (/ xrefList)
 (vl-load-com)
 (vlax-for x (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
   (if (= :vlax-true (vla-get-isxref x))
     (setq xrefList (cons (vla-get-name x) xrefList))))
 (vl-sort xrefList '<))

 

 

Simply type (i:xrefList) into the command line, and a list of xrefs within your current drawing will be listed at the command prompt.

 

Hope this helps!

Edited by BlackBox
Added (vl-load-com)
Link to comment
Share on other sites

One of the main things I am picking up on is the use of (vlax) vs. (vla)

 

Excluding the use of vlax-get which will return data types more intuitive to Vanilla AutoLISP, as I noted in the 'tutorial', there is no difference between:

 

(vla-get-<PropertyName> <object>)

and

(vlax-get-property <object> <PropertyName>)

The reason the two methods exist is for when you are interfacing with an object whose properties/methods aren't included in the scope of the AutoCAD type library (for example interfacing with Excel perhaps), and hence the vla-get- function doesn't exist, (similarly for methods).

 

See another example here.

 

All I want (for now) is a list of xrefs to see what xrefs are in my drawing by typing !xreflist at the command prompt. And how to access the xref properties and methods... So I can start experimenting.

 

I would recommend that you look through the whole thread again - there are quite a few examples of functions not requiring arguments which may be run solely to return a list of xrefs (including a set of vanilla autolisp functions).

Link to comment
Share on other sites

As always, I want to thank you all for helping me.

Lee, I took your advice and went back thru the thread.

My confusion came from experience (or the lack there of) on my end that when I copied the code provided, I was getting:

“error: too few arguments”

This error happened on all code until Renderman’s post #12. Which (I am embarrassed to say) I did not try, (sorry Renderman) because I had already convinced myself I did not know how to use the code provided, because they were sub-functions, and there was something else missing.

Renderman, thank you for digging thru the posts and handing me the code.

Link to comment
Share on other sites

This error happened on all code until Renderman’s post #12. Which (I am embarrassed to say) I did not try, (sorry Renderman) because I had already convinced myself I did not know how to use the code provided, because they were sub-functions, and there was something else missing.

 

 

No worries, Cadman.

 

Sometimes development jargon is more intimidating than the code itself. Terms like sub-functions, reactors, and lambda are really just 'code' tools, much like a mechanic has a meter, wrench, and screwdriver - each has their own purpose.

 

Admittedly, it is easier to understand something when it is tangible, instead of using your mind's eye. :wink:

 

Renderman, thank you for digging thru the posts and handing me the code.

 

 

Clarity is important to me, and you're welcome. :)

Link to comment
Share on other sites

Lee, I took your advice and went back thru the thread.

My confusion came from experience (or the lack there of) on my end that when I copied the code provided, I was getting:

“error: too few arguments"

 

CADMan,

 

Supplying subfunctions with arguments is not too hard a concept to grasp, as you are doing the same thing everytime you use any "in-built" LISP function.

 

Take the simple 'setq' function, this takes arguments: a symbol and a value to assign to that symbol (and multiple of each of these).

 

Hence, in a sense, when we write subfunctions we are only really extending the library of functions available to you.

 

You use such functions as 'foreach', 'while' - supplying each with necessary arguments, but you don't perhaps need to know how these functions work in themselves.

 

So, for example, take my code from post #4:

 

(defun GetBlockObject ( name )
 (if (tblsearch "BLOCK" name)
   (vla-item
     (vla-get-Blocks
       (vla-get-ActiveDocument
         (vlax-get-acad-object)
       )
     )
     name
   )
 )
)

We know the function needs an argument as it has a symbol located before any appearance of a "/" in the defun statement, e.g.

 

(defun test ( / var1 var2 ) ;; << No argument required, 'var1', 'var2' local variables

(defun test ( arg1 / var1 var2 ) ;; << Argument 'arg1' required, 'var1', 'var2' local variables

(defun test ( arg1 arg2 ) ;; Arguments 'arg1' and 'arg2' required, no local variables

And so, with my code above, the argument 'name' is required - in this context, this refers to the block/xref name.

 

So, when calling the function, just as we would supply 'setq', 'foreach', 'while' with the necessary arguments, we supply 'GetBlockObject' with the block name:

 

(setq symbol "value")

(foreach symbol lst ...)

(GetBlockObject "MyBlockName")

So, as you can see, the concept of supplying arguments to functions really isn't new to you.

Link to comment
Share on other sites

So, as you can see, the concept of supplying arguments to functions really isn't new to you.

 

 

... Stupid jargon. :glare:

 

You see what I did just there? (In the voice of Stewie Griffin) lol

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...